Skip to content

Commit a5c78ce

Browse files
committed
chore: add islate example
1 parent e75110f commit a5c78ce

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

example/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ Future<void> main() async {
3939
}
4040
4141
```
42+
43+
## Other
44+
45+
- [Using Isolate](isolate.dart)

example/isolate.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import 'dart:io';
2+
import 'dart:isolate';
3+
4+
import 'package:spry/spry.dart';
5+
6+
Future<void> runServer([_]) async {
7+
final app = createSpry();
8+
9+
app.get('/', (_) {});
10+
app.post('/user', (_) {});
11+
app.get('/user/:name', (event) => event.params['name']);
12+
13+
final server = app.serve(hostname: '0.0.0.0', port: 3000, reusePort: true);
14+
await server.ready();
15+
}
16+
17+
Future<void> main() async {
18+
// Run main server.
19+
await runServer();
20+
21+
// Run cluster servers.
22+
for (int i = Platform.numberOfProcessors - 1; i > 0; i--) {
23+
await Isolate.spawn(runServer, null);
24+
}
25+
}

0 commit comments

Comments
 (0)