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

Unified Diff: pkg/scheduled_test/lib/src/task.dart

Issue 12209073: Add a scheduled test library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Make everything play nicely with the outside world. 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 side-by-side diff with in-line comments
Download patch
Index: pkg/scheduled_test/lib/src/task.dart
diff --git a/pkg/scheduled_test/lib/src/task.dart b/pkg/scheduled_test/lib/src/task.dart
new file mode 100644
index 0000000000000000000000000000000000000000..558a9cd6f065584177e820a9ab7bbc0dde29bfc8
--- /dev/null
+++ b/pkg/scheduled_test/lib/src/task.dart
@@ -0,0 +1,51 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library task;
+
+import 'dart:async';
+
+import 'schedule.dart';
+import 'utils.dart';
+
+typedef Future TaskBody();
+
+/// A single task to be run as part of a [TaskQueue].
+class Task {
+ /// The queue to which this [Task] belongs.
+ final TaskQueue queue;
+
+ /// A description of this task. Used for debugging. May be `null`.
+ final String description;
+
+ /// The body of the task.
+ TaskBody fn;
+
+ /// The identifier of the task. This is unique within [queue]. It's used for
+ /// debugging when [description] isn't provided.
+ int _id;
+
+ /// A Future that will complete to the return value of [fn] once this task
+ /// finishes running.
+ Future get result => _resultCompleter.future;
+ final _resultCompleter = new Completer();
+
+ Task(fn(), this.queue, this.description) {
+ _id = this.queue.contents.length;
+ this.fn = () {
+ var future = new Future.immediate(null).then((_) => fn());
+ chainToCompleter(future, _resultCompleter);
+ return future;
+ };
+
+ // Make sure any error thrown by fn isn't top-leveled by virtue of being
+ // passed to the result future.
+ result.catchError((_) {});
+ }
+
+ String toString() => description == null ? "#$_id" : description;
+
+ /// Returns a detailed representation of [queue] with this task highlighted.
+ String generateTree() => queue.generateTree(this);
+}

Powered by Google App Engine
This is Rietveld 408576698