kovenant
kovenant copied to clipboard
Nested promise never complete with all
Version nl.komponents.kovenant:kovenant:3.3.0 nl.komponents.kovenant:kovenant-android:3.3.0 Kotlin: 1.2.10 Android Studio 3.0.1 Build #AI-171.4443003, built on November 10, 2017 JRE: 1.8.0_152-release-915-b01 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 7 6.1
Test Code:
val test = mutableListOf<Promise<Int, Exception>>()
test.add(task { task { 1 }.get() })
all(test) success {
// Never called
}
Note that Promise.of(1).get()
works fine but not task { 1 }.get()
.
I can confirm that the inner task has been executed but somehow success is never called. I was trying to use this as fallback task, for example:
task {
cache.get(key) ?: loadFromWebTask(key).get()
}
You could try task { task { 1 } }.unwrap()
.
Do you happen to have Kovenant configured with just one worker thread? Because in that case this indeed will block. It's not a good idea to use blocking methods like get
in a mix with async methods. Like @friendoye suggested, you are probably want to use unwrap
. Or just try to avoid nested Promises al together.
@mplatvoet I used the default number of thread. I have rewritten the code to avoid it though.