question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide Channel.invokeOnClose { ... } function

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Reactions:11
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
elizarovcommented, Jun 26, 2018

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

2reactions
jcornazcommented, Apr 21, 2018

@Groostav your proposition need to consume the channel. What if we want to have an onClose without consuming elements?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found