jdeferred / jdeferred

Java Deferred/Promise library similar to JQuery.

Home Page:jdeferred.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to create rejected promise?

koloboid opened this issue · comments

Hello. Thanks for the project.
So, a little question - how I can create rejected promise? For example:

Promise downloadFile(String url, String localPath) {
        try {
            return downloadFile(new URL(url), localPath);
        } catch (MalformedURLException e) {
            return ????; // I want to return simple rejected Promise, in one line. How?
        }
}
Promise downloadFile(URL url, String localPath) {
        /// ... DeferredAsyncTask, etc
}

Thanks in advice

hiya! since you aren't using generics, you should be able to return something simple like:

return new DeferredObject().reject(e);

Thanks a lot for reply, there are mostly pseudo-code in topic, so without generics.
If you had a few seconds to respond please - is there any call like all()/some() which accepts array of promises? (like Q/bluebird/jquery.when.apply does)

there is something similar, see if this is what you are looking for:
https://github.com/jdeferred/jdeferred/blob/master/README.md#deferred-manager

You should be able to do something like.. dm.when(p1, p2, p3).then(...)

Cheers,