kovenant icon indicating copy to clipboard operation
kovenant copied to clipboard

Nested promise never complete with all

Open joshuaavalon opened this issue 6 years ago • 3 comments

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()
}

joshuaavalon avatar Dec 29 '17 04:12 joshuaavalon

You could try task { task { 1 } }.unwrap().

friendoye avatar Dec 30 '17 22:12 friendoye

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 avatar Jan 02 '18 19:01 mplatvoet

@mplatvoet I used the default number of thread. I have rewritten the code to avoid it though.

joshuaavalon avatar Jan 03 '18 01:01 joshuaavalon