Future 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.
var future = Image.loadFromFile ("image.png");
future.onComplete (function (image) { trace ("Image loaded"); });
future.onProgress (function (loaded, total) { trace ("Loading: " + loaded + ", " + total); });
future.onError (function (error) { trace (error); });
Image.loadFromFile ("image.png").then (function (image) {
return Future.withValue (image.width);
}).onComplete (function (width) { trace (width); })
Future values can be chained together for asynchronous processing of values.
If an error occurs earlier in the chain, the error is propagated to all onError callbacks.
Future will call onComplete callbacks, even if completion occurred before registering the
callback. This resolves race conditions, so even functions that return immediately can return
values using Future.
Future values are meant to be immutable, if you wish to update a Future, you should create one
using a Promise, and use the Promise interface to influence the error, complete or progress state
of a Future.