2017-03-28 23:29:22 +00:00
|
|
|
import 'dart:async';
|
2018-08-21 01:27:39 +00:00
|
|
|
import 'dart:io';
|
2017-03-28 23:29:22 +00:00
|
|
|
import 'dart:isolate';
|
2018-08-21 01:27:39 +00:00
|
|
|
|
2018-08-19 15:33:25 +00:00
|
|
|
import 'package:angel_container/mirrors.dart';
|
2017-03-28 23:29:22 +00:00
|
|
|
import 'package:angel_framework/angel_framework.dart';
|
|
|
|
|
|
|
|
main() async {
|
|
|
|
int x = 0;
|
|
|
|
var c = new Completer();
|
|
|
|
var exit = new ReceivePort();
|
|
|
|
List<Isolate> isolates = [];
|
|
|
|
|
|
|
|
exit.listen((_) {
|
|
|
|
if (++x >= 50) {
|
|
|
|
c.complete();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-08-21 01:27:39 +00:00
|
|
|
for (int i = 1; i < Platform.numberOfProcessors; i++) {
|
2017-03-28 23:29:22 +00:00
|
|
|
var isolate = await Isolate.spawn(serverMain, null);
|
|
|
|
isolates.add(isolate);
|
|
|
|
print('Spawned isolate #${i + 1}...');
|
|
|
|
|
|
|
|
isolate.addOnExitListener(exit.sendPort);
|
|
|
|
}
|
|
|
|
|
2018-08-21 01:27:39 +00:00
|
|
|
serverMain(null);
|
|
|
|
|
2017-03-28 23:29:22 +00:00
|
|
|
print('Angel listening at http://localhost:3000');
|
|
|
|
await c.future;
|
|
|
|
}
|
|
|
|
|
|
|
|
serverMain(_) async {
|
2018-08-20 02:40:11 +00:00
|
|
|
var app = new Angel(reflector: MirrorsReflector());
|
2018-02-07 04:38:26 +00:00
|
|
|
var http = new AngelHttp.custom(app, startShared); // Run a cluster
|
2017-03-28 23:29:22 +00:00
|
|
|
|
2018-08-20 20:21:06 +00:00
|
|
|
app.get('/', (req, res) {
|
|
|
|
res.serialize({
|
|
|
|
"foo": "bar",
|
|
|
|
"one": [2, "three"],
|
|
|
|
"bar": {"baz": "quux"}
|
|
|
|
});
|
2017-03-28 23:29:22 +00:00
|
|
|
});
|
|
|
|
|
2017-10-04 14:09:12 +00:00
|
|
|
app.errorHandler = (e, req, res) {
|
|
|
|
print(e.message ?? e.error ?? e);
|
|
|
|
print(e.stackTrace);
|
|
|
|
};
|
2017-03-28 23:29:22 +00:00
|
|
|
|
2018-06-08 07:06:26 +00:00
|
|
|
var server = await http.startServer('127.0.0.1', 3000);
|
2018-02-07 04:38:26 +00:00
|
|
|
print('Listening at http://${server.address.address}:${server.port}');
|
2017-03-28 23:29:22 +00:00
|
|
|
}
|