What does `Dispatchers.Unconfined` do if it ever ...
# coroutines
m
What does
Dispatchers.Unconfined
do if it ever needs to dispatch ?
Copy code
runBlocking {
      withContext(Dispatchers.Unconfined) {
        withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
          // do something in IO here
        }
        // I am still in an IO thread
        delay(10) // dispatch
        // what thread am I here?
      }
    }
a
you're running synchronously in the call to
continuation.resume()
from whatever caused it to be resumed
m
But what thread is going to call
continuation.resume()
after the 10ms delay?
I get the
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {}
calls me back in
IO
context. But the
delay
, I'm not sure how it's going to resume. I would somehow expect to fallback to the dispatcher from the initial
runBlocking
but that doesn't seem to be the case.
m
Actually, I can reduce the snippet to
Copy code
runBlocking {
      withContext(Dispatchers.Unconfined) {
        delay(10) // dispatch
        // what thread am I here?
      }
    }
Yep,
Default
is what I'm observing
Just not sure if that's a thing I should be relying on or if it's in the "dangerous" zone...
a
basically if you're asking this question for anything other than idle curiosity you probably don't want to be using
Dispatchers.Unconfined
🙂
👍 1
m
Yea, looks like it 🙂
Thanks for the pointers!
👍 1