mplatvoet
10/25/2015, 8:08 AMawait
in Kovenant. Ideally await
is sugar for nested callbacks, just like for comprehensions in Scala. So roughly this:
async {
async { 42 } then {
async {
42 * 2
}
}
}.unwrap().unwrap()
would be equivalent to this:
async {
val n = await async {42}
await async {n * 2 }
}
But I can't do this kind of sugar in Kotlin (yet). So my solution now, with loads of restrictions, is to implement await
as a method that lets the current calling thread execute the next item in the queue of the current worker pool. It works but has a huge issue. This is (potentially) creating a call stack pretty easily. Just have enough task that have a call to await
and every call advances the stack.
I have a branch with all this implemented https://github.com/mplatvoet/kovenant/tree/feature/await
And a test runner https://github.com/mplatvoet/kovenant/blob/feature/await/projects/core/src/test/kotlin/performance/await.kt that produces the StackOverFlow pretty quickly.
Does anyone has an idea how to overcome the stack problem?