2018-07-03 23:16:29 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:isolate';
|
|
|
|
import 'package:angel_framework/angel_framework.dart';
|
|
|
|
import 'package:angel_wings/angel_wings.dart';
|
|
|
|
|
|
|
|
main() async {
|
2018-07-08 22:59:51 +00:00
|
|
|
if (false)
|
2018-07-03 23:16:29 +00:00
|
|
|
for (int i = 1; i < Platform.numberOfProcessors; i++) {
|
|
|
|
var onError = new ReceivePort();
|
|
|
|
Isolate.spawn(isolateMain, i, onError: onError.sendPort);
|
|
|
|
onError.listen((e) => Zone.current
|
|
|
|
.handleUncaughtError(e[0], new StackTrace.fromString(e[1].toString())));
|
|
|
|
}
|
|
|
|
|
|
|
|
isolateMain(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void isolateMain(int id) {
|
|
|
|
var app = new Angel();
|
2018-07-08 22:59:51 +00:00
|
|
|
var wings = new AngelWings(app, shared: id > 0, useZone: false);
|
2018-07-03 23:16:29 +00:00
|
|
|
|
2018-07-08 22:59:51 +00:00
|
|
|
var old = app.errorHandler;
|
|
|
|
app.errorHandler = (e, req, res) {
|
|
|
|
print(e);
|
|
|
|
print(e.stackTrace);
|
|
|
|
return old(e, req, res);
|
|
|
|
};
|
|
|
|
|
|
|
|
app.get('/', 'Hello, native world! This is isolate #$id.');
|
2018-07-03 23:16:29 +00:00
|
|
|
|
|
|
|
wings.startServer('127.0.0.1', 3000).then((_) {
|
|
|
|
print(
|
|
|
|
'Instance #$id listening at http://${wings.address.address}:${wings.port}');
|
|
|
|
});
|
|
|
|
}
|