platform/performance/hello/main.dart

34 lines
872 B
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';
import 'package:angel_framework/angel_framework.dart';
2017-10-28 08:50:16 +00:00
import 'package:angel_framework/metrics.dart';
main() {
2017-11-18 17:42:31 +00:00
for (int i = 0; i < Platform.numberOfProcessors; i++) {
Isolate.spawn(start, i + 1);
2017-10-28 08:50:16 +00:00
}
start(0);
}
void start(int id) {
2017-10-28 08:50:16 +00:00
var app = new AngelMetrics.custom(startShared)
..lazyParseBodies = true
2017-10-28 08:50:16 +00:00
..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);
};
app.startServer(InternetAddress.LOOPBACK_IP_V4, 3000).then((server) {
print(
'Instance #$id listening at http://${server.address.address}:${server.port}');
});
}