How to fail promise in Scala -


in scala documentation, there example how pick future succeeds faster using promises.

http://docs.scala-lang.org/overviews/core/futures.html#promises

def first[t](f: future[t], g: future[t]): future[t] = {   val p = promise[t]   f onsuccess {     case x => p.trysuccess(x)   }   g onsuccess {     case x => p.trysuccess(x)   }   p.future } 

this function returns future succeeds first , if either 1 of them fails, never completes.

is possible modify in way if other future fails, second returned if it's successful , if both of them successful, faster 1 picked code now.

you can add this:

f onfailure {   case e =>     g onfailure {       case _ =>         p.failure(e)     } } 

when both futures failed, fail promise same exception f. can elaborate on create exception records 2 exceptions coming f , g if necessary.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -