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

Side by Side Diff: pkg/scheduled_test/lib/src/task.dart

Issue 12208081: Add a scheduled test library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 library task;
6
7 import 'dart:async';
8
9 import 'schedule.dart';
10 import 'utils.dart';
11
12 /// A single task to be run as part of a [TaskQueue].
13 class Task {
14 /// The queue to which this [Task] belongs.
15 final TaskQueue queue;
16
17 /// A description of this task. Used for debugging. May be `null`.
18 final String description;
19
20 /// The body of the task.
21 Function fn;
Bob Nystrom 2013/02/08 16:15:37 Make a typedef for this: typedef Future TaskBody(
nweiz 2013/02/08 22:14:38 Done.
22
23 /// The identifier of the task. This is unique within [queue]. It's used for
24 /// debugging when [description] isn't provided.
25 int _id;
26
27 /// A Future that will complete to the return value of [fn] once this task
28 /// finishes running.
29 Future get result => _resultCompleter.future;
30 final _resultCompleter = new Completer();
31
32 Task(Future fn(), this.queue, this.description) {
33 _id = this.queue.contents.length;
34 this.fn = () {
35 var future = new Future.immediate(null).then((_) => fn());
36 chainToCompleter(future, _resultCompleter);
37 return future;
38 };
39
40 // Make sure any error thrown by fn isn't top-leveled by virtue of being
41 // passed to the result future.
42 result.catchError((_) {});
43 }
44
45 String toString() => description == null ? "#$_id" : description;
46
47 /// Returns a detailed representation of [queue] with this task highlighted.
48 String generateTree() => queue.generateTree(this);
49 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698