Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate ticker channels into structured concurrency and flows #540

Open
elizarov opened this issue Sep 9, 2018 · 10 comments
Open

Integrate ticker channels into structured concurrency and flows #540

elizarov opened this issue Sep 9, 2018 · 10 comments

Comments

@elizarov
Copy link
Contributor

elizarov commented Sep 9, 2018

We need to integrate ticker channels into a structured concurrency story to make sure they are not lost running forever. They should be somehow marked as "daemon" (?) children of their parent and should not prevent the parent completion, but shall be cancelled when all other (non-daemon?) children coroutines complete. This would make standard timing-related operations easy to write in a less error-prone way.

P.S. This is not critical for 1.0 release, since the API for channels is going to be kept experimental anyway.

@qwwdfsad qwwdfsad added this to the 1.3.0 milestone Apr 7, 2019
@elizarov elizarov removed this from the 1.3.0-alpha milestone Jul 16, 2019
@wyaeld
Copy link

wyaeld commented Sep 2, 2019

@elizarov is this coming? Currently trying to build coroutine-based background processing but having a time-keeping channel will simplify a number of things.

@elizarov
Copy link
Contributor Author

elizarov commented Sep 3, 2019

@wyaeld Yes. Ticker channels will become a part of Flow framework. Yet, this is not going to happen in the short-term future. Actually, flows makes it so easy to write this kind of things yourself, as to almost remove the need for any kind of library primitive.

Can you, please, write more details on what kind of background processing you are doing and what are your use-cases for time-keeping channels.

@elizarov elizarov added the flow label Sep 3, 2019
@wyaeld
Copy link

wyaeld commented Sep 3, 2019 via email

@elizarov
Copy link
Contributor Author

elizarov commented Sep 4, 2019

@wyaeld For your use-case we plan something like a specialized time-based chunked primitive. See #1302

@elizarov elizarov changed the title Integrate ticker channels into structured concurrency Integrate ticker channels into structured concurrency and flows Mar 18, 2020
@esdudnik
Copy link

esdudnik commented Jun 3, 2020

Will ticker channels be multiplatform? I came from this issue
#1186
Looking for something similar for multiplatform library.

@elizarov
Copy link
Contributor Author

elizarov commented Jun 4, 2020

Yes. The plan is to have them flow-based an multiplatform.

@MarcelReiter
Copy link

MarcelReiter commented Mar 1, 2021

Are there any updates?

We'd like to use this feature in an app displaying a one-time-password for two-step-verification similar to the google authenticator

Usually, OTPs are valid 30 seconds, and "start" on a full minute or on a half minute,
e.g. 12:00:00 or 12:00:30, but not 12:00:01

In the moment we're using rx-java and emit:

  • on creation
  • after (first delay), which is the time until the next 30s-interval; e.g. when it's 12:00:03 then the first delay is 27s
  • each 30s after that

@YoshiRulz
Copy link

YoshiRulz commented Jan 19, 2022

If you want another use-case: I'm writing a daemon which periodically checks the audio graph of an (external) PipeWire daemon, and creates or deletes links based on a user-defined ruleset. At the moment I'm struggling to get any timer to work, including the deprecated ticker edit: got it (though I don't understand it, and this is constant-delay not constant-interval). Here's my code:

public fun main(): Unit = runBlocking {
	JVMSoundController().use { soundController ->
		embeddedServer(Netty, port = wsProtocolPort) {
			// ... (the other half of my app, a WebSocket server for remote control)
		}.start()
		flow {
			while (true) {
				emit(Unit)
				delay(3.seconds)
			}
		}.collect {
			soundController.checkLocks()
		}
	}
}

@hugo891
Copy link

hugo891 commented Jun 16, 2022

We need to integrate ticker channels into a structured concurrency story to make sure they are not lost running forever. They should be somehow marked as "daemon" (?) children of their parent and should not prevent the parent completion, but shall be cancelled when all other (non-daemon?) children coroutines complete. This would make standard timing-related operations easy to write in a less error-prone way.

P.S. This is not critical for 1.0 release, since the API for channels is going to be kept experimental anyway.

#540 (comment)

@akuter-bc
Copy link

Hi guys.
Is this still planned on a future release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants