ticker

fun ticker(delayMillis: Long, initialDelayMillis: Long = delayMillis, context: CoroutineContext = EmptyCoroutineContext, mode: TickerMode = TickerMode.FIXED_PERIOD): ReceiveChannel<Unit>(source)

Creates a channel that produces the first item after the given initial delay and subsequent items with the given delay between them.

The resulting channel is a rendezvous channel. When receiver from this channel does not keep up with receiving the elements from this channel, they are not being sent due to backpressure. The actual timing behavior of ticker in this case is controlled by mode parameter which is set to TickerMode.FIXED_PERIOD by default. See TickerMode for other details.

This channel stops producing elements immediately after ReceiveChannel.cancel invocation.

Note producer to this channel is dispatched via Dispatchers.Unconfined by default and started eagerly.

Note: Ticker channels are not currently integrated with structured concurrency and their api will change in the future.

Parameters

delayMillis

delay between each element in milliseconds.

initialDelayMillis

delay after which the first element will be produced (it is equal to delayMillis by default) in milliseconds.

context

context of the producing coroutine.

mode

specifies behavior when elements are not received (FIXED_PERIOD by default).