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.

launchConsumeEach terminal operator (name needed)

See original GitHub issue

ConflatedBroadcastChannel is a good fit for dataflow programming. It represents an asynchronously updatable value and its consuming operation “does the right thing” of delivering the most recent value and all the subsequent update. In the domain of dataflow programming the common operation is to process each value in a separate coroutine. For example, in Android:

val x = ConflatedBroadcastChannel() // a model for some value x

launch(UI) { 
    x.consumeEach { someView.text = it.toString } 
}

This launch(context) { consumeEach { ... } } pattern is very common, so some dedicated terminal operator seems to be in order for it. Possible names are:

launchConsumeEach is an obvious, but verbose choice, see https://github.com/dmytrodanylyk/coroutines-arch/blob/master/library/src/main/java/com/kotlin/arch/ChannelsExt.kt by @dmytrodanylyk

The challenge that we have is that all terminal operators currently defined on ReceiveChannel are suspending functions that work in the context of invoker. All non-suspending operator that receive context as parameter perform some kind of transform and return another representation. This immediately suggests that launchConsumeEach become such an intermediate operator and its result should be a Job. But can we find a better name for it? Some verb in style of the other operators we have?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

3reactions
elizarovcommented, Feb 22, 2019

We’ve been designing the similar operator for #254 cold stream and the idea we’ve decided to go with will be usable for channels, too If you have a channel it would look like this:

channel.asFlow().launchIn(scope) { 
    onEach { it -> action(it) }
    catch<SomeException> { it -> handleException(it) }
    finally { releaseSomeResources() }
}

The other way to use this API would be like this:

scope.launchFlow(channel.asFlow()) { 
    // same DSL here
}
1reaction
elizarovcommented, Aug 2, 2019

A correction: The released replacement for the proposed channel.launchConsumeEach(scope) { block } is channel.asFlow().onEach { block }.launchIn(scope)

Read more comments on GitHub >

github_iconTop Results From Across the Web

TERMINAL OPERATOR MONTHLY RETURN General ...
The Terminal Operator Monthly Return must be filed by those licensees who operate ... Indicate any changes to the company name and address...
Read more >
Cal. Code Regs. tit. 17 § 93130.9 - Casetext
Section 93130.9 - Terminal Operator Requirements. Terminal operators that receive ocean-going vessels in California shall meet the following requirements.
Read more >
FT-941.1 - Tax.NY.gov
Name of terminal operator. Federal employer identification number (EIN). Terminal location (street and city). Part 1 – Reconciliation for each type of fuel....
Read more >
Terminal Operator - South Dakota Department of Revenue
The Terminal Operator license is required if a business is operating as a motor fuel pipeline terminal in the state. A separate license...
Read more >
Terminal Operator Report - DOL
Terminal code. Reporting period. Postmark date. Month. Year. Report type. No operations Amended report. Cancel license (date effective):. Name and address.
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