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

Unified Diff: pkg/barback/lib/src/asset_node.dart

Issue 187263003: Move Barback to a more thoroughly push-based model. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 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
« no previous file with comments | « pkg/barback/lib/src/asset_cascade.dart ('k') | pkg/barback/lib/src/group_runner.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/asset_node.dart
diff --git a/pkg/barback/lib/src/asset_node.dart b/pkg/barback/lib/src/asset_node.dart
index c4aec846a054e33ac5bb588531bee94d30874709..5e794431a6d283f9f74cad9db38edf3e2b0fa174 100644
--- a/pkg/barback/lib/src/asset_node.dart
+++ b/pkg/barback/lib/src/asset_node.dart
@@ -96,35 +96,13 @@ class AssetNode {
Future whenRemoved(callback()) =>
_waitForState((state) => state.isRemoved, (_) => callback());
- /// Runs [callback] repeatedly until the node's asset has maintained the same
- /// value for the duration.
+ /// Returns a [Future] that completes when [state] changes from its current
+ /// value to any other value.
///
- /// This will run [callback] as soon as the asset is available (synchronously
- /// if it's available immediately). If the [state] changes at all while
- /// waiting for the Future returned by [callback] to complete, it will be
- /// re-run as soon as it completes and the asset is available again. This will
- /// continue until [state] doesn't change at all.
- ///
- /// If this asset is removed, this will throw an [AssetNotFoundException] as
- /// soon as [callback]'s Future is finished running.
- Future tryUntilStable(Future callback(Asset asset)) {
- return whenAvailable((asset) {
- var modifiedDuringCallback = false;
- var subscription;
- subscription = onStateChange.listen((_) {
- modifiedDuringCallback = true;
- subscription.cancel();
- });
-
- return callback(asset).then((result) {
- subscription.cancel();
-
- // If the asset was modified at all while running the callback, the
- // result was invalid and we should try again.
- if (modifiedDuringCallback) return tryUntilStable(callback);
- return result;
- });
- });
+ /// The returned [Future] will contain the new state.
+ Future<AssetState> whenStateChanges() {
+ var startState = state;
+ return _waitForState((state) => state != startState, (state) => state);
}
/// Calls [callback] as soon as the node is in a state that matches [test].
« no previous file with comments | « pkg/barback/lib/src/asset_cascade.dart ('k') | pkg/barback/lib/src/group_runner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698