How to wait till all promises complete
johneke opened this issue · comments
I currently have code like this:
DeferredManager d = new DefaultDeferredManager();
dman
.when(new DeferredObject().reject(""), new DeferredObject().promise(), new DeferredObject().promise())
.then(new DoneCallback<MultipleResults>()
{
@Override
public void onDone(MultipleResults result)
{
System.out.println("done called");
}
})
.fail(new FailCallback<OneReject>()
{
@Override
public void onFail(OneReject result)
{
System.out.println("fail called");
}
})
.always(new AlwaysCallback<MultipleResults, OneReject>()
{
@Override
public void onAlways(Promise.State state, MultipleResults resolved, OneReject rejected)
{
System.out.println("always called");
}
});
I am noticing that right away onFail
gets called and onAlways
gets called, since the first promise is rejected. It doesn't matter that all other promises in the chain are pending.
This is fine, but is there any way I can wait for all promises in the deferred manager to resolve/reject? And then collect them all together? I am looking for something similar to when.settle()
in when.js
This sounds like a good enhancement!
Haha sounds good, I assumed it was possible and I just didn't know how to do it.
Ill work on a PR! Thanks!
done #118