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

Side by Side Diff: packages/isolate/lib/runner.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 months 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
« no previous file with comments | « packages/isolate/lib/registry.dart ('k') | packages/isolate/lib/src/errors.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// A [Runner] runs a function, potentially in a different scope
6 /// or even isolate.
7 library isolate.runner;
8
9 import 'dart:async' show Future;
10
11 /// Calls a function with an argument.
12 ///
13 /// The function can be run in a different place from where the `Runner`
14 /// resides, e.g., in a different isolate.
15 class Runner {
16 /// Request that [function] be called with the provided arguments.
17 ///
18 /// The arguments will be applied to the function in the same way as by
19 /// [Function.apply], but it may happen in a different isolate or setting.
20 ///
21 /// It's necessary that the function can be sent through a [SendPort]
22 /// if the call is performed in another isolate.
23 /// That means the other isolate should be created using [Isolate.spawn]
24 /// so that it is running the same code as the sending isolate,
25 /// and the function must be a static or top-level function.
26 ///
27 /// Waits for the result of the call, and completes the returned future
28 /// with the result, whether it's a value or an error.
29 ///
30 /// If the returned future does not complete before `timeLimit` has passed,
31 /// the [onTimeout] action is executed instead, and its result (whether it
32 /// returns or throws) is used as the result of the returned future.
33 ///
34 /// If `onTimeout` is omitted, a timeout will cause the returned future to
35 /// complete with a [TimeoutException].
36 ///
37 /// The default implementation runs the function in the current isolate.
38 Future run(function(argument), Object argument,
39 {Duration timeout, onTimeout()}) {
40 Future result = new Future.sync(() => function(argument));
41 if (timeout != null) {
42 result = result.timeout(timeout, onTimeout: onTimeout);
43 }
44 return result;
45 }
46
47 /// Stop the runner.
48 ///
49 /// If the runner has allocated resources, e.g., an isolate, it should
50 /// be released. No further calls to [run] should be made after calling
51 /// stop.
52 Future close() => new Future.value();
53 }
OLDNEW
« no previous file with comments | « packages/isolate/lib/registry.dart ('k') | packages/isolate/lib/src/errors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698