Why is the last `log` showing a `DefaultExecutor` ...
# coroutines
r
Why is the last
log
showing a
DefaultExecutor
context and not
SINGLE-THREAD
?
e
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
@elizarov can't it be the compiler mixing/messing the two coroutines we have here?
r
@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
Looking at it…
r
e
Phew… not a bug.. figured it out. I’ll write in the issue
r
Looks like the context is correct, but the Thread isn't.
Ok cool
e
You shutdown the executor too early (with
use
). It cannot execute anymore, so default executor is used.
l
So you can remove the
bug
tag @elizarov 😉
r
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
@rocketraman You can just not use the
.use
extension
r
Ah
l
As long as nothing stops the thread, you are free to use it
👍 1
d
Does it make sense to default to the DefaultExecutor instead of throwing?
e
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.