OLD | NEW |
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 part of dart.isolate; | 5 part of dart.isolate; |
6 | 6 |
7 /** | 7 /** |
8 * The initial [IsolateStream] available by default for this isolate. This | 8 * The initial [IsolateStream] available by default for this isolate. This |
9 * [IsolateStream] is created automatically and it is commonly used to establish | 9 * [IsolateStream] is created automatically and it is commonly used to establish |
10 * the first communication between isolates (see [streamSpawnFunction] and | 10 * the first communication between isolates (see [streamSpawnFunction] and |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 /** | 32 /** |
33 * [IsolateStream]s, together with [IsolateSink]s, are the only means of | 33 * [IsolateStream]s, together with [IsolateSink]s, are the only means of |
34 * communication between isolates. Each IsolateStream has a corresponding | 34 * communication between isolates. Each IsolateStream has a corresponding |
35 * [IsolateSink]. Any message written into that sink will be delivered to | 35 * [IsolateSink]. Any message written into that sink will be delivered to |
36 * the stream and then dispatched to the stream's subscribers. | 36 * the stream and then dispatched to the stream's subscribers. |
37 */ | 37 */ |
38 class IsolateStream extends Stream<dynamic> { | 38 class IsolateStream extends Stream<dynamic> { |
39 bool _isClosed = false; | 39 bool _isClosed = false; |
40 final ReceivePort _port; | 40 final ReceivePort _port; |
41 StreamController _controller = new StreamController(); | 41 StreamController _controller = new StreamController(sync: true); |
42 | 42 |
43 IsolateStream._fromOriginalReceivePort(this._port) { | 43 IsolateStream._fromOriginalReceivePort(this._port) { |
44 _port.receive((message, replyTo) { | 44 _port.receive((message, replyTo) { |
45 assert(replyTo == null); | 45 assert(replyTo == null); |
46 _add(message); | 46 _add(message); |
47 }); | 47 }); |
48 } | 48 } |
49 | 49 |
50 IsolateStream._fromOriginalReceivePortOneShot(this._port) { | 50 IsolateStream._fromOriginalReceivePortOneShot(this._port) { |
51 _port.receive((message, replyTo) { | 51 _port.receive((message, replyTo) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 * default stream. | 141 * default stream. |
142 * | 142 * |
143 * The optional [unhandledExceptionCallback] argument is invoked whenever an | 143 * The optional [unhandledExceptionCallback] argument is invoked whenever an |
144 * exception inside the isolate is unhandled. It can be seen as a big | 144 * exception inside the isolate is unhandled. It can be seen as a big |
145 * `try/catch` around everything that is executed inside the isolate. The | 145 * `try/catch` around everything that is executed inside the isolate. The |
146 * callback should return `true` when it was able to handled the exception. | 146 * callback should return `true` when it was able to handled the exception. |
147 */ | 147 */ |
148 external IsolateSink streamSpawnFunction( | 148 external IsolateSink streamSpawnFunction( |
149 void topLevelFunction(), | 149 void topLevelFunction(), |
150 [bool unhandledExceptionCallback(IsolateUnhandledException e)]); | 150 [bool unhandledExceptionCallback(IsolateUnhandledException e)]); |
OLD | NEW |