concurrency - How to add callbacks to Future in Scala? -


i saw example here:

 val fut = future { ... // body function } // body function starts here fut oncomplete { ... // callback } 

looks may add callback after completion of body function. still invoked ? anyway, prefer add callbacks future before function starts running. make sense ? how can ?

if want control point of execution of future, chain promise.

import scala.concurrent._ import executioncontext.implicits.global  val initialpromise = promise[unit]  // add computations val fut = initialpromise.future map { _ => println("my future") }  // register callbacks fut oncomplete { _ => println("my callback") }  // run initialpromise.success() 

using other unit allows feed computation arbitrary values.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -