Provide Channel.invokeOnClose { ... } function
See original GitHub issueI’m currently writing an Android library that maps Bluetooth Low Energy scan callbacks to a ReceiveChannel
.
I’d like to be able to detect when the channel becomes closed for receive and for send so I can stop the scan, but it didn’t find any onClose { ... }
function on Channel
. Is there a reason it is not present, and could it be added in the future?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:10 (8 by maintainers)
Top Results From Across the Web
invokeOnClose - GitHub Pages
Registers a handler which is synchronously invoked once the channel is closed or the receiving side of this channel is cancelled.
Read more >SendChannel - Javadoc.io
When the clause is selected the reference to this channel is passed into the corresponding block. void, invokeOnClose(kotlin.jvm.functions.
Read more >Kotlin Coroutines in Android — Channel - Medium
Channel could be considered to provide a stream of values between coroutines ... The function name is very readable, one coroutine could use ......
Read more >Close a Coroutine channel when consumer's Job is cancelled
Marking function as suspend doesn't make it a coroutine. Here's one way to fix this with structured concurrency: class Producer: CoroutineScope ...
Read more >Going deep on Flows & Channels — Part 3 - ProAndroidDev
This is all you need to understand how Channels work, so give ... The invokeOnClose() method is invoked automatically when the Sender closes...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve explained a workaround solution to the missing
invokeOnClose
in this SO answer: https://stackoverflow.com/questions/51029737/handle-cancelation-inside-kotlin-coroutines-producer/51041980#51041980@Groostav your proposition need to consume the channel. What if we want to have an
onClose
without consuming elements?