2024-09-23 01:44:59 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:isolate';
|
|
|
|
import 'package:platform_framework/platform_framework.dart';
|
|
|
|
import 'package:platform_framework/http.dart';
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
var x = 0;
|
|
|
|
var c = Completer();
|
|
|
|
var exit = ReceivePort();
|
|
|
|
var isolates = <Isolate>[];
|
|
|
|
|
|
|
|
exit.listen((_) {
|
|
|
|
if (++x >= 50) {
|
|
|
|
c.complete();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
for (var i = 1; i < Platform.numberOfProcessors; i++) {
|
|
|
|
var isolate = await Isolate.spawn(serverMain, null);
|
|
|
|
isolates.add(isolate);
|
|
|
|
print('Spawned isolate #${i + 1}...');
|
|
|
|
|
|
|
|
isolate.addOnExitListener(exit.sendPort);
|
|
|
|
}
|
|
|
|
|
|
|
|
serverMain(null);
|
|
|
|
|
2024-09-23 04:39:29 +00:00
|
|
|
print('Protevus listening at http://localhost:3000');
|
2024-09-23 01:44:59 +00:00
|
|
|
await c.future;
|
|
|
|
}
|
|
|
|
|
|
|
|
void serverMain(_) async {
|
2024-09-23 04:39:29 +00:00
|
|
|
var app = Protevus();
|
2024-09-23 01:44:59 +00:00
|
|
|
var http =
|
2024-09-23 04:39:29 +00:00
|
|
|
ProtevusHttp.custom(app, startShared, useZone: false); // Run a cluster
|
2024-09-23 01:44:59 +00:00
|
|
|
|
|
|
|
app.get('/', (req, res) {
|
|
|
|
return res.serialize({
|
|
|
|
'foo': 'bar',
|
|
|
|
'one': [2, 'three'],
|
|
|
|
'bar': {'baz': 'quux'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.errorHandler = (e, req, res) {
|
|
|
|
print(e.message);
|
|
|
|
print(e.stackTrace);
|
|
|
|
};
|
|
|
|
|
|
|
|
var server = await http.startServer('127.0.0.1', 3000);
|
|
|
|
print('Listening at http://${server.address.address}:${server.port}');
|
|
|
|
}
|