Comments (7)
Fixed in develop
branch
from kotlinx.coroutines.
Hm... ConflatedBroadcastChannel
is well, conflated. If you have two back-to-back invocations to put
with different keys, then the second offer
will replace the previous one (it will be conflated) and the waiter will never wake up.
There is no await/notify-like not event-like mechanism in coroutines out-of-the-bix yet. Mutex
should support conditions but it does not do so now, so you'll leave this ticket open.
If wonder what is the larger context of the problem that you are trying to solve with AwaitableMap
. What are you planning to use it for?
from kotlinx.coroutines.
Thanks for your quick reply. As far as I understood, there is no problem for me to use the conflated version as I am not using the value transmitted for anything. The offer() should just wake up very listener that currently is "subscribed" by having a channel open. I'm not sure why the waiter would not wake up if any put is broadcasted to all the receivers.
Moreover, I still think there is a bug in the implementation of ConflatedBroadcastChannel somewhere because it works well in most cases but in higher loads, the put-replacement routine gets stuck in an infinite loop in offer which is considered to be a non-blocking call. In no case, offer() should do that.
My use case is the following. I have an object that several child objects that are to be loaded asynchronously via HTTP (slow) but I want to update new items in the UI as soon as they are completely fetched by the coroutine. There is another coroutine that already knows that the will be there as some point in the future, waiting for its arrival (this one is calling the await() method). It will then process the item data before displaying it on the UI.
I wrote a workaround that uses a map of channels, that works for my use-case right now, but is not generic.
I'm fairly new to Kotlin and Android programming, but I think Kotlin and coroutines are just wonderful :) Maybe there are already implementations that I'm not aware of (I haven't checked out RxJava yet)...
from kotlinx.coroutines.
The stuck invocation to offer
is definitely a bug. Thanks for the report!
I've just cursory glanced over your code and how I see how you are actually using it. I was misled by the fact that you send a key to the channel, but you don't actually use this key in await
. Indeed, you use ConflatedBroadcastChannel
as a simple event mechanism to notify waiter that something had changed. It should work this way, though a more efficient event-like mechanism is definitely needed (but is missing now).
from kotlinx.coroutines.
Good news. I can reproduce your problem (offer
hangs) with a stress test.
from kotlinx.coroutines.
Thanks a lot for the quick fix. Will stick to the alternate solution until next release though and then test it again. Your changes don't seem trivial, though :) Feel free to close the issue, if you think the stress test covers the problem.
from kotlinx.coroutines.
It turned out to be a whole complex of problems that happen when you concurrently close/send/close channels. It was also independently discovered by @cy6erGn0m
from kotlinx.coroutines.
Related Issues (20)
- Add optional support for Micrometer Context Propagation
- `withContext` may execute code in the wrong context if the `coroutineContext` misleads it HOT 3
- SharedFlow doesn't have same parameters as in constructor function HOT 2
- Consider deprecation cycle for `CoroutineDispatcher.invoke` HOT 6
- How to prevent a SharedFlow collect values when the activity resumes? HOT 1
- Consider discouraging `CoroutineStart.LAZY`
- Some problem about `addLast` in LockFreeTaskQueue HOT 1
- Maybe it's reasonable to recommend wrapping a `callbackFlow` initialization into `try`-`finally`? HOT 4
- Dispatcher failures may leave coroutines uncompleted HOT 1
- `DelayWithTimeoutDiagnostics` missing from R8 rules? HOT 3
- Introduce Flow.all/any/none operators HOT 3
- [WASM] JsException: Exception was thrown while running JavaScript code kotlinx.coroutines.error_$external_fun HOT 6
- Suppressed exceptions are lost during stacktrace recovery HOT 1
- `runBlocking` executes other tasks instead of its own HOT 1
- "Kotlin Compiler Error: NoClassDefFoundError for kotlin/reflect/full/KClasses during Gradle build" HOT 1
- Add argument to sample to sample at the start of a flow instead of the end? HOT 5
- Mapping a list asynchronously HOT 2
- rx Flowable that use Unconfined dispatcher result in a deadlock when using a runblocking() that execute a suspend function with (Semaphore, mutex or ReentrantLock) HOT 1
- Some way of subscribe to shared flow without slowing-down others HOT 7
- Wrong function's return type called inside lambda when using launch HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kotlinx.coroutines.