`Unconfined` context gives you similar, but not re...
# coroutines
e
Unconfined
context gives you similar, but not really the same behavior as Rx. Consider the following pipeline:
Copy code
produce(Context1) { ... }.map(Unconfined) { ... }.consume(Context2) { ... }
So, you have a producer running in one thread and a consumer in another thread, with unconfined transformer in between. What thread the transformer runs in? The answer — it depends. With standard channel implementations from
kotlinx.coroutines
the transformer sometimes runs in one thread, sometimes in the other. If the producer is faster than the consumer, then the producer is resuming suspended transformer coroutine, thus the transformer runs in the first thread. However, if the consumer is faster than the producer, then the consumer is resuming suspended transformer coroutine and thus transformer runs in the second thread. In order to imitate Rx behavior you either have to explicitly inherit producer’s context or exercise special care about the kinds of channels you are using in between the coroutines.
👍 2