-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
42 lines (36 loc) · 1.17 KB
/
main.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
// Copyright (c) 2012, 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:async';
import 'dart:isolate';
import 'dart-ext:sample_extension';
// A class caches the native port used to call an asynchronous extension.
class RandomArray {
static SendPort _port;
Future<String> randomArray() {
var completer = new Completer<String>();
var replyPort = new RawReceivePort();
var args = new List(1);
args[0] = replyPort.sendPort;
_servicePort.send(args);
replyPort.handler = (result) {
replyPort.close(); // <- This is never reached!!!!
if (result != null) {
completer.complete(result);
} else {
completer.completeError(new Exception("Random array creation failed"));
}
};
return completer.future;
}
SendPort get _servicePort {
if (_port == null) {
_port = _newServicePort();
}
return _port;
}
SendPort _newServicePort() native "RandomArray_ServicePort";
}
Future main(List<String> args) async {
print(await RandomArray().randomArray());
}