mplatvoet
09/27/2015, 5:47 AMawait
construct to Kovenant, but this is actually really tricky. The expected behaviour of an await
call in most languages is not to block but to let the calling thread do other work and continue later. Otherwise we just could make a call to get()
(which does block). Furthermore, blocking shouldn’t be done inside a async
block since you can create a deadlock situation that way.
So this is what we want:
async {
val a1 = await(p1)
val a2 = await(p2(a1))
//...etc
}
The tricky part is the implementation of await
itself. It should give control back to the Dispatcher. The easiest way is to introduce a method on Dispatchers to help along and do one task from the queue. But not all dispatchers can be made to help along. If you create a Dispatcher from e.g. an Executor you won’t always be able to provide such method. I think in that case await should throw some Unsupported Operation Exception. But that is not really user friendly. What do you think?