Created
July 1, 2013 21:34
-
-
Save tconkling/5904846 to your computer and use it in GitHub Desktop.
TaskSequencer using react
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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