https://kotlinlang.org logo
Title
r

rocketraman

07/10/2018, 5:18 PM
Why is the last
log
showing a
DefaultExecutor
context and not
SINGLE-THREAD
?
e

elizarov

07/10/2018, 5:21 PM
It is definitely a bug. Can you, please, file it. Looks like we broke something in
withContext
in one of the recent updates.
(very bad that it was not caught by tests)
l

louiscad

07/10/2018, 5:23 PM
@elizarov can't it be the compiler mixing/messing the two coroutines we have here?
r

rocketraman

07/10/2018, 5:23 PM
@elizarov Thought I was going crazy. Will file it. This seems to be causing a hang in my program. What is my best workaround?
e

elizarov

07/10/2018, 5:26 PM
Looking at it…
r

rocketraman

07/10/2018, 5:28 PM
e

elizarov

07/10/2018, 5:39 PM
Phew… not a bug.. figured it out. I’ll write in the issue
r

rocketraman

07/10/2018, 5:40 PM
Looks like the context is correct, but the Thread isn't.
Ok cool
e

elizarov

07/10/2018, 5:43 PM
You shutdown the executor too early (with
use
). It cannot execute anymore, so default executor is used.
l

louiscad

07/10/2018, 5:43 PM
So you can remove the
bug
tag @elizarov 😉
r

rocketraman

07/10/2018, 5:44 PM
Ah, because
launch
returns before it completes. That makes sense.
@elizarov The solution of moving
join
up works for the example I gave, but in my actual app, the
newSingleThreadContext
is instantiated from non-coroutine code, which needs to be call this code and continue. Therefore I can't join the
launch
. I guess I could always start a Thread that does nothing but do the
launch
+
join
(or
runBlocking
really), but that seems really messy as now I have a useless thread hanging around. What am I missing?
l

louiscad

07/10/2018, 6:39 PM
@rocketraman You can just not use the
.use
extension
r

rocketraman

07/10/2018, 6:40 PM
Ah
l

louiscad

07/10/2018, 6:42 PM
As long as nothing stops the thread, you are free to use it
👍 1
d

Daniel Tam

07/12/2018, 12:34 AM
Does it make sense to default to the DefaultExecutor instead of throwing?
e

elizarov

07/12/2018, 7:30 AM
Yes. It does. It would usually happen when coroutine is shutting down, too, and is in the processing of executing its
finally
sections, releasing resources it had acquired. We should run those. That gives us a chance to be able to recover.