java - Building complex promises in Play -


supposed need return promise method, depends on external resource , calculation. imagine like:

promise<integer> foo() {   return ws.url(url)     .getasync()     .callwhenready(new function<httpresponse>(){       integer parse(httpresponse response) {         // parsing business logic          // ...         int parsed = ...;         return parsed;       }   }); }  

what can use callwhenready? jquery.promise() behaves.

i think want f.promise.map (play 2.0.2):

    /**      * maps promise promise of type <code>b</code>.  function <code>function</code> applied      * promise redeemed.      *      * exceptions thrown <code>function</code> wrapped in {@link java.lang.runtimeexception}, unless      * <code>runtimeexception</code>'s themselves.      *      * @param function function map <code>a</code> <code>b</code>.      * @return wrapped promise maps type <code>a</code> <code>b</code>.      */     public <b> promise<b> map(final function<a, b> function) {         return new promise<b>(             promise.map(new scala.runtime.abstractfunction1<a,b>() {                 public b apply(a a) {                     try {                         return function.apply(a);                     } catch (runtimeexception e) {                         throw e;                     } catch(throwable t) {                         throw new runtimeexception(t);                     }                 }             })         );     } 

it seems code you're using earlier version play, think should still able replace callwhenready map (and add integer type parameter callback function).


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -