| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 isolate.isolate_runner; | 5 library isolate.isolate_runner; |
| 6 | 6 |
| 7 import "dart:async"; | 7 import "dart:async"; |
| 8 import "dart:isolate"; | 8 import "dart:isolate"; |
| 9 | 9 |
| 10 import 'ports.dart'; | 10 import 'ports.dart'; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 /// If the isolate is already dead, the returned future will not complete. | 94 /// If the isolate is already dead, the returned future will not complete. |
| 95 /// If that may be the case, use [Future.timeout] on the returned future | 95 /// If that may be the case, use [Future.timeout] on the returned future |
| 96 /// to take extra action after a while. Example: | 96 /// to take extra action after a while. Example: |
| 97 /// | 97 /// |
| 98 /// var f = isolate.kill(); | 98 /// var f = isolate.kill(); |
| 99 /// f.then((_) => print('Dead') | 99 /// f.then((_) => print('Dead') |
| 100 /// .timeout(new Duration(...), onTimeout: () => print('No response')); | 100 /// .timeout(new Duration(...), onTimeout: () => print('No response')); |
| 101 Future kill({Duration timeout: const Duration(seconds: 1)}) { | 101 Future kill({Duration timeout: const Duration(seconds: 1)}) { |
| 102 Future onExit = singleResponseFuture(isolate.addOnExitListener); | 102 Future onExit = singleResponseFuture(isolate.addOnExitListener); |
| 103 if (Duration.ZERO == timeout) { | 103 if (Duration.ZERO == timeout) { |
| 104 isolate.kill(Isolate.IMMEDIATE); | 104 isolate.kill(priority: Isolate.IMMEDIATE); |
| 105 return onExit; | 105 return onExit; |
| 106 } else { | 106 } else { |
| 107 // Try a more gentle shutdown sequence. | 107 // Try a more gentle shutdown sequence. |
| 108 _commandPort.send(list1(_SHUTDOWN)); | 108 _commandPort.send(list1(_SHUTDOWN)); |
| 109 return onExit.timeout(timeout, onTimeout: () { | 109 return onExit.timeout(timeout, onTimeout: () { |
| 110 isolate.kill(Isolate.IMMEDIATE); | 110 isolate.kill(priority: Isolate.IMMEDIATE); |
| 111 return onExit; | 111 return onExit; |
| 112 }); | 112 }); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 /// Queries the isolate on whether it's alive. | 116 /// Queries the isolate on whether it's alive. |
| 117 /// | 117 /// |
| 118 /// If the isolate is alive and responding to commands, the | 118 /// If the isolate is alive and responding to commands, the |
| 119 /// returned future completes with `true`. | 119 /// returned future completes with `true`. |
| 120 /// | 120 /// |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 case _RUN: | 288 case _RUN: |
| 289 Function function = command[1]; | 289 Function function = command[1]; |
| 290 var argument = command[2]; | 290 var argument = command[2]; |
| 291 SendPort responsePort = command[3]; | 291 SendPort responsePort = command[3]; |
| 292 sendFutureResult(new Future.sync(() => function(argument)), | 292 sendFutureResult(new Future.sync(() => function(argument)), |
| 293 responsePort); | 293 responsePort); |
| 294 return; | 294 return; |
| 295 } | 295 } |
| 296 } | 296 } |
| 297 } | 297 } |
| OLD | NEW |