Name |
Ceylon Promise Platform Module |
||||||
---|---|---|---|---|---|---|---|
Category |
SDK
The Ceylon SDK |
||||||
Backends | JVM JavaScript | ||||||
Maven coordinates | org.ceylon-lang:ceylon.promise | ||||||
Compatible Ceylon release |
JVM: 1.2.x, 1.3.x (latest) JavaScript: Unknown (10/0) |
||||||
Published | Aug 21, 2017 | ||||||
Stats |
Downloads (JVM): 615 Downloads (JS): 133 Source downloads: 426 |
||||||
Authors |
Julien Viet |
||||||
License | Apache Software License | ||||||
Description |
Support for promises. If an operation cannot return a value immediately without blocking, it may instead return a promise of the value. A promise is an object that represents the return value or the thrown exception that the operation eventually produces. Such an operation is sometimes called a long-running operation. This module provides following abstractions:
PromisesA
The method Promise<Document> promise = queryDocumentById(id); promise.completed { (d) => print("Got the document: " + d.title); (e) => print("Document was not received: " + e.message); }; The first function is called the Returning promisesA The instance of The value deferred = Deferred<String>(); return deferred.promise; The
For example: value deferred = Deferred<String>(); void doOperation() { try { String val = getValue(); deferred.fulfill(val); } catch (Throwable e) { deferred.reject(e); } } Chaining promisesWhen chaining is needed the method When invoking the For example: Promise<Integer> promiseOfInteger = newPromiseOfInteger(); Promise<String> promiseOfString = promiseOfInteger.map(Integer.string); promiseOfString.map((s) => print("Completed with " + s)); Or, more concisely: newPromiseOfInteger() .map(Integer.string) .map((s) => print("Completed with " + s)); Composing promisesPromises can be composed into a single promise that is fulfilled when every one of the individual composed promises is fulfilled. If one of the promise is rejected then the composed promise is rejected. Promise<String> promiseOfString = newPromiseOfString(); Promise<Integer> promiseOfInteger = newPromiseOfInteger(); (promiseOfString.and(promiseOfInteger)).completed { (i, s) => print("All fulfilled"); (e) => print("One failed"); }; Notice that:
The
|
||||||
Dependencies |
|
||||||
Usage |
import ceylon.promise "1.3.3"; |
||||||
Module links |
Members Imported By Home Code repository Issue tracker Browse Download .car Download .js Download source archive Download module documentation View API documentation |