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); });

Constructor

new()

Create a new Promise instance

Variables

read onlyfuture:Future<T>

The Future associated with this Promise.

All subsequent calls to set an error, completion or progress state will update the status and notify listeners to this Future

read onlyisComplete:Bool

Whether the Promise (and related Future) has finished with a completion state. This will be false if the Promise has not been resolved with a completion or error state.

read onlyisError:Bool

Whether the Promise (and related Future) has finished with an error state. This will be false if the Promise has not been resolved with a completion or error state.

Methods

complete(data:T):Promise<T>

Resolves this Promise with a completion state

Parameters:

data

The completion value

Returns:

The current Promise

completeWith(future:Future<T>):Promise<T>

Resolves this Promise with the complete, error and/or progress state of another Future

Parameters:

future

The Future to use to resolve this Promise

Returns:

The current Promise

error(msg:Dynamic):Promise<T>

Resolves this Promise with an error state

Parameters:

msg

The error value

Returns:

The current Promise

progress(progress:Int, total:Int):Promise<T>

Sends progress updates to the related Future

Parameters:

progress

A progress value

total

A total value. This should be equal or greater to the progress value

Returns:

The current Promise