Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: samples/sample_extension/sample_asynchronous_extension.dart

Issue 43483004: Remove the reply port form the native isolate handler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library sample_asynchronous_extension; 5 library sample_asynchronous_extension;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 import 'dart-ext:sample_extension'; 9 import 'dart-ext:sample_extension';
10 10
11 // A class caches the native port used to call an asynchronous extension. 11 // A class caches the native port used to call an asynchronous extension.
12 class RandomArray { 12 class RandomArray {
13 static SendPort _port; 13 static SendPort _port;
14 14
15 Future<List<int> > randomArray(int seed, int length) { 15 Future<List<int> > randomArray(int seed, int length) {
16 var args = new List(2); 16 var completer = new Completer();
17 var replyPort = new ReceivePort();
floitsch 2013/10/25 18:04:58 This will need to be merged to new RawReceivePort(
Søren Gjesse 2013/10/29 07:42:57 Done.
18 var args = new List(3);
17 args[0] = seed; 19 args[0] = seed;
18 args[1] = length; 20 args[1] = length;
19 return _servicePort.call(args).then((result) { 21 args[2] = replyPort.toSendPort();
22 _servicePort.send(args);
23 replyPort.receive((result, _) {
24 replyPort.close();
20 if (result != null) { 25 if (result != null) {
21 return result; 26 completer.complete(result);
22 } else { 27 } else {
23 throw new Exception("Random array creation failed"); 28 completer.completeError(new Exception("Random array creation failed"));
24 } 29 }
25 }); 30 });
31 return completer.future;
26 } 32 }
27 33
28 SendPort get _servicePort { 34 SendPort get _servicePort {
29 if (_port == null) { 35 if (_port == null) {
30 _port = _newServicePort(); 36 _port = _newServicePort();
31 } 37 }
32 return _port; 38 return _port;
33 } 39 }
34 40
35 SendPort _newServicePort() native "RandomArray_ServicePort"; 41 SendPort _newServicePort() native "RandomArray_ServicePort";
36 } 42 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698