Convert a Java Future to a Scala Future -


i have java future object convert scala future. looking @ j.u.c.future api, there nothing use other isdone method. isdone method blocking?

currently have in mind:

val p = promise() if(javafuture.isdone())   p.success(javafuture.get) 

is there better way this?

how wrapping (i'm assuming there's implicit executioncontext here):

val scalafuture = future {     javafuture.get } 

edit:

a simple polling strategy (java.util.future => f):

def pollforresult[t](f: f[t]): future[t] = future {     thread.sleep(500)     f   }.flatmap(f => if (f.isdone) future { f.get } else pollforresult(f)) 

this check if java future done every 500ms. total blocking time same above (rounded nearest 500ms) solution allow other tasks interleaved in same thread of executioncontext.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -