public class RSVP extends Object
| Constructor and Description |
|---|
RSVP() |
| Modifier and Type | Method and Description |
|---|---|
static <Result,FailResponse> |
all(org.stjs.javascript.Array<Promise<Result,FailResponse>> promises)
Sometimes you might want to work with many promises at once.
|
static <Result,FailResponse> |
allSettled(org.stjs.javascript.Array<Promise<Result,FailResponse>> promises)
Creates a new Promise that is fulfilled when all of the specified promises are either fulfilled or rejected.
|
static Object |
configure(String optionName)
Reads the value of an option of RSVP
|
static void |
configure(String optionName,
Object value)
Configures an option of RSVP.
|
static <Result,FailResponse> |
defer()
Sometimes one needs to create a deferred object, without immediately specifying how it will be resolved.
|
static <FailResponse> |
hash(org.stjs.javascript.Map<String,Promise<Object,FailResponse>> promises)
If you need to reference many promises at once (like all()), but would like to avoid encoding the actual promise
order you can use hash().
|
static <Result,FailResponse> |
hashSettled(org.stjs.javascript.Map<String,Promise<Result,FailResponse>> promises)
Creates a new Promise that is fulfilled when all of the specified promises are either fulfilled or rejected.
|
static void |
on(String eventType,
org.stjs.javascript.functions.Callback1<PromiseEvent> callback1)
Add a global listener for all promises on a specific type of event.
|
public static <Result,FailResponse> Deferred<Result,FailResponse> defer()
Deferred<String, Error> deferred = RSVP.defer();
// ...
deferred.promise // access the promise
// ...
deferred.resolve("Hello");
The RSVP.Promise constructor is generally a better, less error-prone choice than RSVP.defer().
Promises are recommended unless the specific properties of deferred are needed.public static <Result,FailResponse> Promise<org.stjs.javascript.Array<Result>,FailResponse> all(org.stjs.javascript.Array<Promise<Result,FailResponse>> promises)
Array> promises = $array(2, 3, 5, 7, 11, 13).map(id -> { return getJSON("/post/" + id + ".json"); }); RSVP.all(promises).then(posts -> { // posts contains an array of results for the given promises }, error -> { // if any of the promises fails. } );
public static <FailResponse> Promise<org.stjs.javascript.Map<String,Object>,FailResponse> hash(org.stjs.javascript.Map<String,Promise<Object,FailResponse>> promises)
Map> promises = $map ( "posts", getJSON("/posts.json"), "users", getJSON("/users.json") ); RSVP.hash(promises).then(results -> { console.log(results.$get("users")); // print the users.json results console.log(results.$get("posts")); // print the posts.json results });
public static <Result,FailResponse> Promise<org.stjs.javascript.Array<SettleResult<Result,FailResponse>>,Void> allSettled(org.stjs.javascript.Array<Promise<Result,FailResponse>> promises)
public static <Result,FailResponse> Promise<org.stjs.javascript.Map<String,SettleResult<Result,FailResponse>>,Void> hashSettled(org.stjs.javascript.Map<String,Promise<Result,FailResponse>> promises)
public static void on(String eventType, org.stjs.javascript.functions.Callback1<PromiseEvent> callback1)
eventType - one of ['created', 'chained', 'fulfilled', 'rejected']callback1 - a callback that is called whenever the specified event is triggered on any promisepublic static void configure(String optionName, Object value)
RSVP.configure('instrument', true | false);
// capturing the stacks is slow, so you also have to opt in
RSVP.configure('instrument-with-stack', true | false);
optionName - the name of the option to configurevalue - the value of the optionCopyright © 2015. All Rights Reserved.