Promise
is an implementation of Futures and Promises, with the exception that
in addition to "success" and "failure" states (represented as "complete" and "error"),
Lime Future
introduces "progress" feedback as well to increase the value of
Future
values.
While Future
is meant to be read-only, Promise
can be used to set the state of a future
for receipients of it's Future
object. For example:
function examplePromise ():Future<String> {
var promise = new Promise<String> ();
var progress = 0, total = 10;
var timer = new Timer (100);
timer.run = function () {
promise.progress (progress, total);
progress++;
if (progress == total) {
promise.complete ("Done!");
timer.stop ();
}
};
return promise.future;
}
var future = examplePromise ();
future.onComplete (function (message) { trace (message); });
future.onProgress (function (loaded, total) { trace ("Progress: " + loaded + ", " + total); });