platform/performance/hello/main.dart

44 lines
1.1 KiB
Dart
Raw Normal View History

/// A basic server that prints "Hello, world!"
library performance.hello;
2017-11-18 17:42:31 +00:00
import 'dart:async';
import 'dart:io';
import 'dart:isolate';
2018-08-19 15:33:25 +00:00
import 'package:angel_container/mirrors.dart';
import 'package:angel_framework/angel_framework.dart';
2018-10-22 15:54:41 +00:00
import 'package:angel_framework/http.dart';
2017-11-28 18:14:50 +00:00
main() async {
var isolates = <Isolate>[];
2017-11-18 17:42:31 +00:00
for (int i = 0; i < Platform.numberOfProcessors; i++) {
2017-11-28 18:14:50 +00:00
isolates.add(await Isolate.spawn(start, i + 1));
2017-10-28 08:50:16 +00:00
}
2017-11-28 18:14:50 +00:00
await Future.wait(isolates.map((i) {
var rcv = new ReceivePort();
i.addOnExitListener(rcv.sendPort);
return rcv.first;
}));
//start(0);
}
void start(int id) {
2018-11-15 21:21:46 +00:00
var app = new Angel();
2018-06-08 07:06:26 +00:00
var http = new AngelHttp.custom(app, startShared, useZone: false);
2017-11-28 18:14:50 +00:00
app.get('/', (req, res) => res.write('Hello, world!'));
2017-09-22 14:53:49 +00:00
var oldHandler = app.errorHandler;
app.errorHandler = (e, req, res) {
print('Oops: ${e.error ?? e}');
print(e.stackTrace);
return oldHandler(e, req, res);
};
2018-02-07 05:36:24 +00:00
2018-06-08 07:06:26 +00:00
http.startServer('127.0.0.1', 3000).then((server) {
2018-07-12 15:19:25 +00:00
print(
'Instance #$id listening at http://${server.address.address}:${server.port}');
});
}