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 /** | 5 /** |
6 * A [Runner] runs a function, potentially in a different scope | 6 * A [Runner] runs a function, potentially in a different scope |
7 * or even isolate. | 7 * or even isolate. |
8 */ | 8 */ |
9 library dart.pkg.isolate.runner; | 9 library dart.pkg.isolate.runner; |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... | |
35 * If the returned future does not complete before `timeLimit` has passed, | 35 * If the returned future does not complete before `timeLimit` has passed, |
36 * the [onTimeout] action is executed instead, and its result (whether it | 36 * the [onTimeout] action is executed instead, and its result (whether it |
37 * returns or throws) is used as the result of the returned future. | 37 * returns or throws) is used as the result of the returned future. |
38 * | 38 * |
39 * If `onTimeout` is omitted, a timeout will cause the returned future to | 39 * If `onTimeout` is omitted, a timeout will cause the returned future to |
40 * complete with a [TimeoutException]. | 40 * complete with a [TimeoutException]. |
41 * | 41 * |
42 * The default implementation runs the function in the current isolate. | 42 * The default implementation runs the function in the current isolate. |
43 */ | 43 */ |
44 Future run(function(argument), Object argument, | 44 Future run(function(argument), Object argument, |
45 {Duration timeout, onTimeout()}) { | 45 {Duration timeout, onTimeout()}) { |
Lasse Reichstein Nielsen
2015/02/26 10:59:15
Indent as original.
| |
46 Future result = new Future.sync(() => function(argument)); | 46 Future result = new Future.sync(() => function(argument)); |
47 if (timeout != null) { | 47 if (timeout != null) { |
48 result = result.timeout(timeout, onTimeout: onTimeout); | 48 result = result.timeout(timeout, onTimeout: onTimeout); |
49 } | 49 } |
50 return result; | 50 return result; |
51 } | 51 } |
52 | 52 |
53 /** | 53 /** |
54 * Stop the runner. | 54 * Stop the runner. |
55 * | 55 * |
56 * If the runner has allocated resources, e.g., an isolate, it should | 56 * If the runner has allocated resources, e.g., an isolate, it should |
57 * be released. No further calls to [run] should be made after calling | 57 * be released. No further calls to [run] should be made after calling |
58 * stop. | 58 * stop. |
59 */ | 59 */ |
60 Future close() => new Future.value(); | 60 Future close() => new Future.value(); |
61 } | 61 } |
OLD | NEW |