-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathsample_isolates.dart
53 lines (43 loc) · 1.07 KB
/
sample_isolates.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:isolate';
void main(List<String> args) async {
var arr = newArray(5);
var arr2 = newArray(417);
var hash1 = newHash(5);
var hash2 = newHash(417);
// ignore unused
arr.length;
arr2.length;
hash1.length;
hash2.length;
startIsolate(1);
startIsolate(2);
startIsolate(3);
startIsolate(4);
await Future.delayed(Duration(seconds: 5));
print('at end of main...');
}
void startIsolate(int val) {
Isolate.spawn<int>(isolateEntry, val);
}
Future isolateEntry(int message) async {
print('starting $message');
await Future.delayed(Duration(seconds: message));
print('ending $message');
}
List newArray(int length) {
List l = [];
for (int i = 0; i < length; i++) {
l.add('entry_$i');
}
return l;
}
Map newHash(int length) {
Map m = {};
for (int i = 0; i < length; i++) {
m['entry_$i'] = i;
}
return m;
}