Skip to content

Instantly share code, notes, and snippets.

@tconkling
Created July 1, 2013 21:34
Show Gist options
  • Save tconkling/5904846 to your computer and use it in GitHub Desktop.
Save tconkling/5904846 to your computer and use it in GitHub Desktop.
TaskSequencer using react
//
// aciv-core
package aciv.util {
import aspire.util.F;
import react.Future;
import react.Promise;
public class TaskSequencer
{
/**
* Adds a task to the scheduler. 'task' is a function that optionally receives a
* Promise object. If task takes a Promise, it must call succeed on that Promise when
* its work is complete. If task takes no arguments, then it's considered complete
* as soon as it returns.
*/
public function addTask (task :Function) :void {
if (task.length == 1) {
var promise :Promise = Promise.create();
var last :Future = _last;
_last = promise;
last.onSuccess(F.callback(task, promise));
} else {
_last.onSuccess(F.callback(task));
}
}
protected var _last :Future = Future.success();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment