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

Unified Diff: packages/async/lib/src/async_memoizer.dart

Issue 1521693002: Roll Observatory deps (charted -> ^0.3.0) (Closed) Base URL: https://chromium.googlesource.com/external/github.com/dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « packages/async/lib/async.dart ('k') | packages/async/lib/src/cancelable_operation.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/async/lib/src/async_memoizer.dart
diff --git a/packages/async/lib/src/async_memoizer.dart b/packages/async/lib/src/async_memoizer.dart
index 68a6c80e4fac0372e0bef576076aa599e22348c3..41c3dae87a46054708456ced01a04d582891cb07 100644
--- a/packages/async/lib/src/async_memoizer.dart
+++ b/packages/async/lib/src/async_memoizer.dart
@@ -31,17 +31,18 @@ import 'dart:async';
class AsyncMemoizer<T> {
/// The future containing the method's result.
///
- /// This will be `null` if [run] hasn't been called yet.
- Future<T> _future;
+ /// This can be accessed at any time, and will fire once [runOnce] is called.
+ Future<T> get future => _completer.future;
+ final _completer = new Completer();
/// Whether [run] has been called yet.
- bool get hasRun => _future != null;
+ bool get hasRun => _completer.isCompleted;
/// Runs the function, [computation], if it hasn't been run before.
///
/// If [run] has already been called, this returns the original result.
Future<T> runOnce(computation()) {
- if (_future == null) _future = new Future.sync(computation);
- return _future;
+ if (!hasRun) _completer.complete(new Future.sync(computation));
+ return future;
}
}
« no previous file with comments | « packages/async/lib/async.dart ('k') | packages/async/lib/src/cancelable_operation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698