Promises
A Promise represents a value that may not yet be computed. Any object that implements TAsyncPromise
can be used as a Promise.
Promises can be chained and the type of the new chained promise depends on the state of chainable promise. In total there are the following kinds of Promises:
A Promise created from an existing value or a promise whose computation is succesfully finished is called fulfilled:
fulfilledPromise <gtExample> <return: #AsyncFulfilledPromise> ^ 42 asAsyncPromise
A Promise created from an Exception
or a promise whose computation failed is called rejected:
rejectedPromise <gtExample> <return: #AsyncRejectedPromise> ^ [ 1 / 0 ] on: Error do: #asAsyncPromise
A Promise with a not yet computed value is called pending. Once computation is finished a pending promise becomes fulfilled or rejected:
promiseResolvingToString <gtExample> <return: #AsyncFuturePromise> ^ [ 2 seconds wait. 'Promised value' ] asAsyncPromise
promiseWithError <gtExample> <return: #AsyncFuturePromise> ^ [ 2 seconds wait. 1 / 0 ] asAsyncPromise