Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Flow context preserving property, thread safety and context changing #1210
For example, the following code will produce ISE on the first attempt to launch it:
This is the desired property, but it is not enough to provide the best possible experience for developers.
For example (and I've seen this in the wild), one may want to write the following
it passes context preservation check, it works under the single-threaded dispatcher (and on Android most of the tests are single-threaded), but it produces the least expected error (probably
Originally reported by @gildor
Consider the following system-wide function to work with any resources:
And it doesn't work because it violates context preservation. And one cannot simply use
Strengthen context preservation property. Prohibit not only context element changes, but also situations when emission happens from the different coroutines (efficiently prohibiting situation from #1).
But to allow writing such simple
The full signature:
The only change required to write concurrent or context-ignorant builder is replacing
It was decided to provide a channel-based builder instead of thread-safe one for the sake of consistent mental model:
The only serious downside is Java interoperability: