js.lang.Promise Maven / Gradle / Ivy
package js.lang;
import js.util.collections.Array;
import js.util.function.JsConsumer;
import js.util.iterable.JsIterable;
import org.teavm.jso.JSBody;
/**
* Represents the completion of an asynchronous operation
*
* @param the type parameter
*/
public abstract class Promise extends PromiseLike {
/**
* Prototype promise.
*
* @return the promise
*/
@JSBody(script = "return Promise.prototype")
public static Promise prototype() {
throw new UnsupportedOperationException("Available only in JavaScript");
}
/**
* Creates a new Promise.
*
* @param the type parameter
* @param executor A callback used to initialize the promise. This callback is passed two arguments:
* a resolve callback used to resolve the promise with a value or the result of another promise,
* and a reject callback used to reject the promise with a provided reason or error.
*
* @return the promise
*/
@JSBody(params = "executor", script = "return new Promise(executor)")
public static Promise create(JsConsumer> executor) {
throw new UnsupportedOperationException("Available only in JavaScript");
}
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
*
* @param the type parameter
* @param values An array of Promises.
*
* @return A new Promise.
*/
@JSBody(params = "values", script = "return Promise.all(values)")
public static Promise> all(PromiseLike... values) {
throw new UnsupportedOperationException("Available only in JavaScript");
}
/**
* All promise.
*
* @param the type parameter
* @param values the values
*
* @return the promise
*/
@JSBody(params = "values", script = "return Promise.all(values)")
public static Promise> all(Array> values) {
throw new UnsupportedOperationException("Available only in JavaScript");
}
/**
* All promise.
*
* @param the type parameter
* @param values the values
*
* @return the promise
*/
@JSBody(params = "values", script = "return Promise.all(values)")
public static Promise> all(JsIterable> values) {
throw new UnsupportedOperationException("Available only in JavaScript");
}
/**
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
* or rejected.
*
* @param the type parameter
* @param values An array of Promises.
*
* @return A new Promise.
*/
@JSBody(params = "values", script = "return Promise.race(values)")
public static Promise race(JsIterable> values) {
throw new UnsupportedOperationException("Available only in JavaScript");
}
/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
*
* @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected.
*
* @return A Promise for the completion of which ever callback is executed.
*/
public native Promise then(FullfilledValueCallback onfulfilled, RejectedValueCallback onrejected);
public native Promise then(FullfilledValueCallback onfulfilled);
public native VoidPromise then(FullfilledValueVoidCallback onfulfilled, RejectedValueVoidCallback onrejected);
public native VoidPromise then(FullfilledValueVoidCallback onfulfilled);
public native BooleanPromise then(FullfilledValueBooleanCallback onfulfilled, RejectedValueBooleanCallback onrejected);
public native BooleanPromise then(FullfilledValueBooleanCallback onfulfilled);
public native StringPromise then(FullfilledValueStringCallback onfulfilled, RejectedValueStringCallback onrejected);
public native StringPromise then(FullfilledValueStringCallback onfulfilled);
public native IntPromise then(FullfilledValueIntCallback onfulfilled, RejectedValueIntCallback onrejected);
public native IntPromise then(FullfilledValueIntCallback onfulfilled);
public native DoublePromise then(FullfilledValueDoubleCallback onfulfilled, RejectedValueDoubleCallback onrejected);
public native DoublePromise then(FullfilledValueDoubleCallback onfulfilled);
/**
* Attaches a callback for only the rejection of the Promise.
*
* @param the type parameter
* @param onrejected The callback to execute when the Promise is rejected.
*
* @return A Promise for the completion of the callback.
*/
@JSBody(params = "onrejected", script = "return this.catch(onrejected)")
public native Promise catchError(RejectedValueCallback onrejected);
/**
* Catch error void promise.
*
* @param onrejected the onrejected
*
* @return the void promise
*/
@JSBody(params = "onrejected", script = "return this.catch(onrejected)")
public native VoidPromise catchError(RejectedValueVoidCallback onrejected);
/**
* Catch error boolean promise.
*
* @param onrejected the onrejected
*
* @return the boolean promise
*/
@JSBody(params = "onrejected", script = "return this.catch(onrejected)")
public native BooleanPromise catchError(RejectedValueBooleanCallback onrejected);
/**
* Catch error string promise.
*
* @param onrejected the onrejected
*
* @return the string promise
*/
@JSBody(params = "onrejected", script = "return this.catch(onrejected)")
public native StringPromise catchError(RejectedValueStringCallback onrejected);
/**
* Catch error int promise.
*
* @param onrejected the onrejected
*
* @return the int promise
*/
@JSBody(params = "onrejected", script = "return this.catch(onrejected)")
public native IntPromise catchError(RejectedValueIntCallback onrejected);
/**
* Catch error double promise.
*
* @param onrejected the onrejected
*
* @return the double promise
*/
@JSBody(params = "onrejected", script = "return this.catch(onrejected)")
public native DoublePromise catchError(RejectedValueDoubleCallback onrejected);
/**
* The interface Promise executor.
*
* @param the type parameter
*/
public interface PromiseExecutor extends Any {
/**
* Resolve.
*
* @param value the value
*/
void resolve(T value);
/**
* Resolve.
*
* @param value the value
*/
void resolve(PromiseLike value);
/**
* Resolve.
*/
void resolve();
/**
* Reject.
*
* @param reason the reason
*/
void reject(Any reason);
/**
* Reject.
*/
void reject();
}
}