future - Scala - ScheduledFuture -
i trying implement scheduled future in scala. wait specific time , execute body. far tried following, simple approach
val d = 5.seconds.fromnow val f = future {await.ready(promise().future, d.timeleft); 1} val res = await.result(f, duration.inf) but getting timeoutexcpetion on future. correct approach or should use scheduledexecutor java?
you change code this:
val d = 5.seconds.fromnow val f = future {delay(d); 1} val res = await.result(f, duration.inf) def delay(dur:deadline) = { try(await.ready(promise().future, dur.timeleft)) } but not recommend it. in doing so, blocking in future (blocking wait promise never complete), , think blocking in executioncontext discouraged. either using java scheduled executor stated or using akka @alex23 recommended.
Comments
Post a Comment