Flow

ox.flow.Flow
See theFlow companion object
class Flow[+T](val last: FlowStage[T]) extends FlowOps[T], FlowRunOps[T], FlowIOOps[T], FlowTextOps[T]

Describes an asynchronous transformation pipeline. When run, emits elements of type T.

A flow is lazy - evaluation happens only when it's run.

Flows can be created using the Flow.usingSink, Flow.fromValues and other Flow.from* methods, Flow.tick etc.

Transformation stages can be added using the available combinators, such as Flow.map, Flow.async, Flow.grouped, etc. Each such method returns a new immutable Flow instance.

Running a flow is possible using one of the run* methods, such as Flow.runToList, Flow.runToChannel or Flow.runFold.

Attributes

Companion
object
Graph
Supertypes
trait FlowTextOps[T]
trait FlowIOOps[T]
trait FlowRunOps[T]
class FlowOps[T]
class Object
trait Matchable
class Any
Show all

Members list

Value members

Inherited methods

def alsoTo[U >: T](other: Sink[U]): Flow[U]

Attaches the given ox.channels.Sink to this flow, meaning elements that pass through will also be sent to the sink. If emitting an element, or sending to the other sink blocks, no elements will be processed until both are done. The elements are first emitted by the flow and then, only if that was successful, to the other sink.

Attaches the given ox.channels.Sink to this flow, meaning elements that pass through will also be sent to the sink. If emitting an element, or sending to the other sink blocks, no elements will be processed until both are done. The elements are first emitted by the flow and then, only if that was successful, to the other sink.

If this flow fails, then failure is passed to the other sink as well. If the other sink is failed or complete, this becomes a failure of the returned flow (contrary to alsoToTap where it's ignored).

Value parameters

other

The sink to which elements from this flow will be sent.

Attributes

See also

alsoToTap for a version that drops elements when the other sink is not available for receive.

Inherited from:
FlowOps
def alsoToTap[U >: T](other: Sink[U]): Flow[U]

Attaches the given ox.channels.Sink to this flow, meaning elements that pass through will also be sent to the sink. If the other sink is not available for receive, the elements are still emitted by the returned flow, but not sent to the other sink.

Attaches the given ox.channels.Sink to this flow, meaning elements that pass through will also be sent to the sink. If the other sink is not available for receive, the elements are still emitted by the returned flow, but not sent to the other sink.

If this flow fails, then failure is passed to the other sink as well. If the other sink fails or closes, then failure or closure is ignored and it doesn't affect the resulting flow (contrary to alsoTo where it's propagated).

Value parameters

other

The sink to which elements from this source will be sent.

Attributes

See also

alsoTo for a version that ensures that elements are emitted both by the returned flow and sent to the other sink.

Inherited from:
FlowOps
def async()(using BufferCapacity): Flow[T]

When run, the current pipeline is run asynchornously in the background, emitting elements to a buffer. The elements of the buffer are then emitted by the returned flow.

When run, the current pipeline is run asynchornously in the background, emitting elements to a buffer. The elements of the buffer are then emitted by the returned flow.

The size of the buffer is determined by the BufferCapacity that is in scope.

Any exceptions are propagated by the returned flow.

Attributes

Inherited from:
FlowOps
def collect[U](f: PartialFunction[T, U]): Flow[U]

Applies the given mapping function f to each element emitted by this flow, for which the function is defined, and emits the result. If f is not defined at an element, the element will be skipped.

Applies the given mapping function f to each element emitted by this flow, for which the function is defined, and emits the result. If f is not defined at an element, the element will be skipped.

Value parameters

f

The mapping function.

Attributes

Inherited from:
FlowOps
def concat[U >: T](other: Flow[U]): Flow[U]

Concatenates this flow with the other flow. The resulting flow will emit elements from this flow first, and then from the other flow.

Concatenates this flow with the other flow. The resulting flow will emit elements from this flow first, and then from the other flow.

Value parameters

other

The flow to be appended to this flow.

Attributes

Inherited from:
FlowOps
def decodeStringUtf8(using T <:< Chunk[Byte]): Flow[String]

Decodes a stream of chunks of bytes into UTF-8 Strings. This function is able to handle UTF-8 characters encoded on multiple bytes that are split across chunks.

Decodes a stream of chunks of bytes into UTF-8 Strings. This function is able to handle UTF-8 characters encoded on multiple bytes that are split across chunks.

Attributes

Returns

a flow of Strings decoded from incoming bytes.

Inherited from:
FlowTextOps
def drain(): Flow[Nothing]

Discard all elements emitted by this flow. The returned flow completes only when this flow completes (successfully or with an error).

Discard all elements emitted by this flow. The returned flow completes only when this flow completes (successfully or with an error).

Attributes

Inherited from:
FlowOps
def drop(n: Int): Flow[T]

Drops n elements from this flow and emits subsequent elements.

Drops n elements from this flow and emits subsequent elements.

Value parameters

n

Number of elements to be dropped.

Attributes

Inherited from:
FlowOps
def encodeUtf8(using T <:< String): Flow[Chunk[Byte]]

Encodes a flow of String in to a flow of bytes using UTF-8.

Encodes a flow of String in to a flow of bytes using UTF-8.

Attributes

Inherited from:
FlowTextOps
def filter(f: T => Boolean): Flow[T]

Emits only those elements emitted by this flow, for which f returns true.

Emits only those elements emitted by this flow, for which f returns true.

Value parameters

f

The filtering function.

Attributes

Inherited from:
FlowOps
def flatten[U](using T <:< Flow[U])(using BufferCapacity): Flow[U]

Pipes the elements of child flows into the output source. If the parent source or any of the child sources emit an error, the pulling stops and the output source emits the error.

Pipes the elements of child flows into the output source. If the parent source or any of the child sources emit an error, the pulling stops and the output source emits the error.

Runs all flows concurrently in the background. The size of the buffers is determined by the BufferCapacity that is in scope.

Attributes

Inherited from:
FlowOps
def grouped(n: Int): Flow[Seq[T]]

Chunks up the elements into groups of the specified size. The last group may be smaller due to the flow being complete.

Chunks up the elements into groups of the specified size. The last group may be smaller due to the flow being complete.

Value parameters

n

The number of elements in a group.

Attributes

Inherited from:
FlowOps
def groupedWeighted(minWeight: Long)(costFn: T => Long): Flow[Seq[T]]

Chunks up the elements into groups that have a cumulative weight greater or equal to the minWeight. The last group may be smaller due to the flow being complete.

Chunks up the elements into groups that have a cumulative weight greater or equal to the minWeight. The last group may be smaller due to the flow being complete.

Value parameters

costFn

The function that calculates the weight of an element.

minWeight

The minimum cumulative weight of elements in a group.

Attributes

Inherited from:
FlowOps
def groupedWeightedWithin(minWeight: Long, duration: FiniteDuration)(costFn: T => Long)(using BufferCapacity): Flow[Seq[T]]

Chunks up the emitted elements into groups, within a time window, or limited by the cumulative weight being greater or equal to the minWeight, whatever happens first. The timeout is reset after a group is emitted. If timeout expires and the buffer is empty, nothing is emitted. As soon as a new element is received, the flow will emit it as a single-element group and reset the timer.

Chunks up the emitted elements into groups, within a time window, or limited by the cumulative weight being greater or equal to the minWeight, whatever happens first. The timeout is reset after a group is emitted. If timeout expires and the buffer is empty, nothing is emitted. As soon as a new element is received, the flow will emit it as a single-element group and reset the timer.

Value parameters

costFn

The function that calculates the weight of an element.

duration

The time window in which the elements are grouped.

minWeight

The minimum cumulative weight of elements in a group if no timeout happens.

Attributes

Inherited from:
FlowOps
def groupedWithin(n: Int, duration: FiniteDuration)(using BufferCapacity): Flow[Seq[T]]

Chunks up the emitted elements into groups, within a time window, or limited by the specified number of elements, whatever happens first. The timeout is reset after a group is emitted. If timeout expires and the buffer is empty, nothing is emitted. As soon as a new element is emitted, the flow will emit it as a single-element group and reset the timer.

Chunks up the emitted elements into groups, within a time window, or limited by the specified number of elements, whatever happens first. The timeout is reset after a group is emitted. If timeout expires and the buffer is empty, nothing is emitted. As soon as a new element is emitted, the flow will emit it as a single-element group and reset the timer.

Value parameters

duration

The time window in which the elements are grouped.

n

The maximum number of elements in a group.

Attributes

Inherited from:
FlowOps
def interleave[U >: T](other: Flow[U], segmentSize: Int, eagerComplete: Boolean)(using BufferCapacity): Flow[U]

Emits a given number of elements (determined byc segmentSize) from this flow to the returned flow, then emits the same number of elements from the other flow and repeats. The order of elements in both flows is preserved.

Emits a given number of elements (determined byc segmentSize) from this flow to the returned flow, then emits the same number of elements from the other flow and repeats. The order of elements in both flows is preserved.

If one of the flows is done before the other, the behavior depends on the eagerCancel flag. When set to true, the returned flow is completed immediately, otherwise the remaining elements from the other flow are emitted by the returned flow.

Both flows are run concurrently and asynchronously.

Value parameters

eagerComplete

If true, the returned flow is completed as soon as either of the flow completes. If false, the remaining elements of the non-completed flow are sent downstream.

other

The flow whose elements will be interleaved with the elements of this flow.

segmentSize

The number of elements sent from each flow before switching to the other one. Default is 1.

Attributes

Inherited from:
FlowOps
def intersperse[U >: T](start: U, inject: U, end: U): Flow[U]

Intersperses elements emitted by this flow with inject elements. The start element is emitted at the beginning; end is emitted after the current flow emits the last element.

Intersperses elements emitted by this flow with inject elements. The start element is emitted at the beginning; end is emitted after the current flow emits the last element.

Value parameters

end

An element to be emitted at the end.

inject

An element to be injected between the flow elements.

start

An element to be emitted at the beginning.

Attributes

Inherited from:
FlowOps
def intersperse[U >: T](inject: U): Flow[U]

Intersperses elements emitted by this flow with inject elements. The inject element is emitted between each pair of elements.

Intersperses elements emitted by this flow with inject elements. The inject element is emitted between each pair of elements.

Attributes

Inherited from:
FlowOps
def lines(charset: Charset)(using T <:< Chunk[Byte]): Flow[String]

Transforms a flow of byte chunks such that each emitted String is a text line from the input.

Transforms a flow of byte chunks such that each emitted String is a text line from the input.

Value parameters

charset

the charset to use for decoding the bytes into text.

Attributes

Returns

a flow emitting lines read from the input byte chunks, assuming they represent text.

Inherited from:
FlowTextOps
def linesUtf8(using T <:< Chunk[Byte]): Flow[String]

Transforms a flow of byte chunks such that each emitted String is a text line from the input decoded using UTF-8 charset.

Transforms a flow of byte chunks such that each emitted String is a text line from the input decoded using UTF-8 charset.

Attributes

Returns

a flow emitting lines read from the input byte chunks, assuming they represent text.

Inherited from:
FlowTextOps
def map[U](f: T => U): Flow[U]

Applies the given mapping function f to each element emitted by this flow. The returned flow then emits the results.

Applies the given mapping function f to each element emitted by this flow. The returned flow then emits the results.

Value parameters

f

The mapping function.

Attributes

Inherited from:
FlowOps
def mapConcat[U](f: T => IterableOnce[U]): Flow[U]

Applies the given mapping function f, to each element emitted by this source, transforming it into an IterableOnce of results, then the returned flow emits the results one by one. Can be used to unfold incoming sequences of elements into single elements.

Applies the given mapping function f, to each element emitted by this source, transforming it into an IterableOnce of results, then the returned flow emits the results one by one. Can be used to unfold incoming sequences of elements into single elements.

Value parameters

f

A function that transforms the element from this flow into an IterableOnce of results which are emitted one by one by the returned flow. If the result of f is empty, nothing is emitted by the returned channel.

Attributes

Inherited from:
FlowOps
def mapPar[U](parallelism: Int)(f: T => U)(using BufferCapacity): Flow[U]

Applies the given mapping function f to each element emitted by this flow. At most parallelism invocations of f are run in parallel.

Applies the given mapping function f to each element emitted by this flow. At most parallelism invocations of f are run in parallel.

The mapped results are emitted in the same order, in which inputs are received. In other words, ordering is preserved.

Value parameters

f

The mapping function.

parallelism

An upper bound on the number of forks that run in parallel. Each fork runs the function f on a single element from the flow.

Attributes

Inherited from:
FlowOps
def mapParUnordered[U](parallelism: Int)(f: T => U)(using BufferCapacity): Flow[U]

Applies the given mapping function f to each element emitted by this flow. At most parallelism invocations of f are run in parallel.

Applies the given mapping function f to each element emitted by this flow. At most parallelism invocations of f are run in parallel.

The mapped results might be emitted out-of-order, depending on the order in which the mapping function completes.

Value parameters

f

The mapping function.

parallelism

An upper bound on the number of forks that run in parallel. Each fork runs the function f on a single element from the flow.

Attributes

Inherited from:
FlowOps
def mapStateful[S, U](initializeState: () => S)(f: (S, T) => (S, U), onComplete: S => Option[U]): Flow[U]

Applies the given mapping function f, using additional state, to each element emitted by this flow. The results are emitted by the returned flow. Optionally the returned flow emits an additional element, possibly based on the final state, once this flow is done.

Applies the given mapping function f, using additional state, to each element emitted by this flow. The results are emitted by the returned flow. Optionally the returned flow emits an additional element, possibly based on the final state, once this flow is done.

The initializeState function is called once when statefulMap is called.

The onComplete function is called once when this flow is done. If it returns a non-empty value, the value will be emitted by the flow, while an empty value will be ignored.

Value parameters

f

A function that transforms the element from this flow and the state into a pair of the next state and the result which is emitted by the returned flow.

initializeState

A function that initializes the state.

onComplete

A function that transforms the final state into an optional element emitted by the returned flow. By default the final state is ignored.

Attributes

Inherited from:
FlowOps
def mapStatefulConcat[S, U](initializeState: () => S)(f: (S, T) => (S, IterableOnce[U]), onComplete: S => Option[U]): Flow[U]

Applies the given mapping function f, using additional state, to each element emitted by this flow. The returned flow emits the results one by one. Optionally the returned flow emits an additional element, possibly based on the final state, once this flow is done.

Applies the given mapping function f, using additional state, to each element emitted by this flow. The returned flow emits the results one by one. Optionally the returned flow emits an additional element, possibly based on the final state, once this flow is done.

The initializeState function is called once when statefulMap is called.

The onComplete function is called once when this flow is done. If it returns a non-empty value, the value will be emitted by the returned flow, while an empty value will be ignored.

Value parameters

f

A function that transforms the element from this flow and the state into a pair of the next state and a scala.collection.IterableOnce of results which are emitted one by one by the returned flow. If the result of f is empty, nothing is emitted by the returned flow.

initializeState

A function that initializes the state.

onComplete

A function that transforms the final state into an optional element emitted by the returned flow. By default the final state is ignored.

Attributes

Inherited from:
FlowOps
def mapUsingEmit[U](f: T => (FlowEmit[U]) => Unit): Flow[U]

Applies the given mapping function f to each element emitted by this flow, in sequence. The given FlowSink can be used to emit an arbirary number of elements.

Applies the given mapping function f to each element emitted by this flow, in sequence. The given FlowSink can be used to emit an arbirary number of elements.

Value parameters

f

The mapping function.

Attributes

Inherited from:
FlowOps
def merge[U >: T](other: Flow[U], propagateDoneLeft: Boolean, propagateDoneRight: Boolean)(using BufferCapacity): Flow[U]

Merges two flows into a single flow. The resulting flow emits elements from both flows in the order they are emitted. If one of the flows completes before the other, the remaining elements from the other flow are emitted by the returned flow. This can be changed with the propagateDoneLeft and propagateDoneRight flags.

Merges two flows into a single flow. The resulting flow emits elements from both flows in the order they are emitted. If one of the flows completes before the other, the remaining elements from the other flow are emitted by the returned flow. This can be changed with the propagateDoneLeft and propagateDoneRight flags.

Both flows are run concurrently in the background. The size of the buffers is determined by the BufferCapacity that is in scope.

Value parameters

other

The flow to be merged with this flow.

propagateDoneLeft

Should the resulting flow complete when the left flow (this) completes, before the other flow. By default false, that is any remaining elements from the other flow are emitted.

propagateDoneRight

Should the resulting flow complete when the right flow (outer) completes, before this flow. By default false, that is any remaining elements from this flow are emitted.

Attributes

Inherited from:
FlowOps
def onComplete(f: => Unit): Flow[T]

Always runs f after the flow completes, whether it's because all elements are emitted, or when there's an error.

Always runs f after the flow completes, whether it's because all elements are emitted, or when there's an error.

Attributes

Inherited from:
FlowOps
def onDone(f: => Unit): Flow[T]

Runs f after the flow completes successfully, that is when all elements are emitted.

Runs f after the flow completes successfully, that is when all elements are emitted.

Attributes

Inherited from:
FlowOps
def onError(f: Throwable => Unit): Flow[T]

Runs f after the flow completes with an error. The error can't be recovered.

Runs f after the flow completes with an error. The error can't be recovered.

Attributes

Inherited from:
FlowOps
def orElse[U >: T](alternative: Flow[U]): Flow[U]

If this flow has no elements then elements from an alternative flow are emitted by the returned flow. If this flow is failed then the returned flow is failed as well.

If this flow has no elements then elements from an alternative flow are emitted by the returned flow. If this flow is failed then the returned flow is failed as well.

Value parameters

alternative

An alternative flow to be used when this flow is empty.

Attributes

Inherited from:
FlowOps
def prepend[U >: T](other: Flow[U]): Flow[U]

Prepends other flow to this source. The resulting flow will emit elements from other flow first, and then from the this flow.

Prepends other flow to this source. The resulting flow will emit elements from other flow first, and then from the this flow.

Value parameters

other

The flow to be prepended to this flow.

Attributes

Inherited from:
FlowOps
def runDrain(): Unit

Ignores all elements emitted by the flow. Blocks until the flow completes.

Ignores all elements emitted by the flow. Blocks until the flow completes.

Attributes

Inherited from:
FlowRunOps
def runFold[U](zero: U)(f: (U, T) => U): U

Uses zero as the current value and applies function f on it and a value emitted by this flow. The returned value is used as the next current value and f is applied again with the next value emitted by the flow. The operation is repeated until the flow emits all elements.

Uses zero as the current value and applies function f on it and a value emitted by this flow. The returned value is used as the next current value and f is applied again with the next value emitted by the flow. The operation is repeated until the flow emits all elements.

Value parameters

f

A binary function (a function that takes two arguments) that is applied to the current value and value emitted by the flow.

zero

An initial value to be used as the first argument to function f call.

Attributes

Returns

Combined value retrieved from running function f on all flow elements in a cumulative manner where result of the previous call is used as an input value to the next.

Inherited from:
FlowRunOps
def runForeach(sink: T => Unit): Unit

Invokes the given function for each emitted element. Blocks until the flow completes.

Invokes the given function for each emitted element. Blocks until the flow completes.

Attributes

Inherited from:
FlowRunOps
def runLast(): T

Returns the last element emitted by this flow, or throws NoSuchElementException when the flow emits no elements (is empty).

Returns the last element emitted by this flow, or throws NoSuchElementException when the flow emits no elements (is empty).

Attributes

Throws
NoSuchElementException

When this flow is empty.

Inherited from:
FlowRunOps
def runLastOption(): Option[T]

Returns the last element emitted by this flow, wrapped in Some, or None when this source is empty.

Returns the last element emitted by this flow, wrapped in Some, or None when this source is empty.

Attributes

Inherited from:
FlowRunOps
def runPipeToSink(sink: Sink[T], propagateDone: Boolean): Unit

Passes each element emitted by this flow to the given sink. Blocks until the flow completes.

Passes each element emitted by this flow to the given sink. Blocks until the flow completes.

Errors are always propagated. Successful flow completion is propagated when propagateDone is set to true.

Attributes

Inherited from:
FlowRunOps
def runReduce[U >: T](f: (U, U) => U): U

Applies function f on the first and the following (if available) elements emitted by this flow. The returned value is used as the next current value and f is applied again with the next value emitted by this source. The operation is repeated until this flow emits all elements. This is similar operation to fold but it uses the first emitted element as zero.

Applies function f on the first and the following (if available) elements emitted by this flow. The returned value is used as the next current value and f is applied again with the next value emitted by this source. The operation is repeated until this flow emits all elements. This is similar operation to fold but it uses the first emitted element as zero.

Value parameters

f

A binary function (a function that takes two arguments) that is applied to the current and next values emitted by this flow.

Attributes

Returns

Combined value retrieved from running function f on all flow elements in a cumulative manner where result of the previous call is used as an input value to the next.

Throws
NoSuchElementException

When this flow is empty.

Inherited from:
FlowRunOps
def runTakeLast(n: Int): List[T]

Returns the list of up to n last elements emitted by this flow. Less than n elements is returned when this flow emits less elements than requested. List.empty is returned when takeLast is called on an empty flow.

Returns the list of up to n last elements emitted by this flow. Less than n elements is returned when this flow emits less elements than requested. List.empty is returned when takeLast is called on an empty flow.

Value parameters

n

Number of elements to be taken from the end of this flow. It is expected that n >= 0.

Attributes

Returns

A list of up to n last elements from this flow.

Inherited from:
FlowRunOps

The flow is run in the background, and each emitted element is sent to a newly created channel, which is then returned as the result of this method.

The flow is run in the background, and each emitted element is sent to a newly created channel, which is then returned as the result of this method.

Must be run within a concurrency scope as a fork is created to run the flow. The size of the buffer is determined by the BufferCapacity that is in scope.

Blocks until the flow completes.

Attributes

Inherited from:
FlowRunOps
def runToEmit(emit: FlowEmit[T]): Unit

Invokes the provided FlowEmit fo reach emitted element. Blocks until the flow completes.

Invokes the provided FlowEmit fo reach emitted element. Blocks until the flow completes.

Attributes

Inherited from:
FlowRunOps
def runToFile(path: Path)(using T <:< Chunk[Byte]): Unit

Writes content of this flow to a file.

Writes content of this flow to a file.

Value parameters

path

Path to the target file. If not exists, it will be created.

Attributes

Inherited from:
FlowIOOps
def runToInputStream()(using T <:< Chunk[Byte])(using Ox, BufferCapacity): InputStream

Runs the flow into a java.io.InputStream.

Runs the flow into a java.io.InputStream.

Must be run within a concurrency scope, as under the hood the flow is run in the background.

Attributes

Inherited from:
FlowIOOps
def runToList(): List[T]

Accumulates all elements emitted by this flow into a list. Blocks until the flow completes.

Accumulates all elements emitted by this flow into a list. Blocks until the flow completes.

Attributes

Inherited from:
FlowRunOps
def runToOutputStream(outputStream: OutputStream)(using T <:< Chunk[Byte]): Unit

Writes content of this flow to an java.io.OutputStream.

Writes content of this flow to an java.io.OutputStream.

Value parameters

outputStream

Target OutputStream to write to. Will be closed after finishing the process or on error.

Attributes

Inherited from:
FlowIOOps
def sliding(n: Int, step: Int): Flow[Seq[T]]

Creates sliding windows of elements from this flow. The window slides by step elements. The last window may be smaller due to flow being completed.

Creates sliding windows of elements from this flow. The window slides by step elements. The last window may be smaller due to flow being completed.

Value parameters

n

The number of elements in a window.

step

The number of elements the window slides by.

Attributes

Inherited from:
FlowOps
def take(n: Int): Flow[T]

Takes the first n elements from this flow and emits them. If the flow completes before emitting n elements, the returned flow completes as well.

Takes the first n elements from this flow and emits them. If the flow completes before emitting n elements, the returned flow completes as well.

Attributes

Inherited from:
FlowOps
def takeWhile(f: T => Boolean, includeFirstFailing: Boolean): Flow[T]

Transform the flow so that it emits elements as long as predicate f is satisfied (returns true). If includeFirstFailing is true, the flow will additionally emit the first element that failed the predicate. After that, the flow will complete as done.

Transform the flow so that it emits elements as long as predicate f is satisfied (returns true). If includeFirstFailing is true, the flow will additionally emit the first element that failed the predicate. After that, the flow will complete as done.

Value parameters

f

A predicate function called on incoming elements.

includeFirstFailing

Whether the flow should also emit the first element that failed the predicate (false by default).

Attributes

Inherited from:
FlowOps
def tap(f: T => Unit): Flow[T]

Applies the given effectful function f to each element emitted by this flow. The returned flow emits the elements unchanged. If f throws an exceptions, the flow fails and propagates the exception.

Applies the given effectful function f to each element emitted by this flow. The returned flow emits the elements unchanged. If f throws an exceptions, the flow fails and propagates the exception.

Attributes

Inherited from:
FlowOps
def throttle(elements: Int, per: FiniteDuration): Flow[T]

Emits elements limiting the throughput to specific number of elements (evenly spaced) per time unit. Note that the element's emission-time time is included in the resulting throughput. For instance having throttle(1, 1.second) and emission of the next element taking Xms means that resulting flow will emit elements every 1s + Xms time. Throttling is not applied to the empty source.

Emits elements limiting the throughput to specific number of elements (evenly spaced) per time unit. Note that the element's emission-time time is included in the resulting throughput. For instance having throttle(1, 1.second) and emission of the next element taking Xms means that resulting flow will emit elements every 1s + Xms time. Throttling is not applied to the empty source.

Value parameters

elements

Number of elements to be emitted. Must be greater than 0.

per

Per time unit. Must be greater or equal to 1 ms.

Attributes

Returns

A flow that emits at most elements per time unit.

Inherited from:
FlowOps
def zip[U](other: Flow[U]): Flow[(T, U)]

Combines elements from this and the other flow into tuples. Completion of either flow completes the returned flow as well. The flows are run concurrently.

Combines elements from this and the other flow into tuples. Completion of either flow completes the returned flow as well. The flows are run concurrently.

Attributes

See also

zipAll

Inherited from:
FlowOps
def zipAll[U >: T, V](other: Flow[V], thisDefault: U, otherDefault: V): Flow[(U, V)]

Combines elements from this and the other flow into tuples, handling early completion of either flow with defaults. The flows are run concurrently.

Combines elements from this and the other flow into tuples, handling early completion of either flow with defaults. The flows are run concurrently.

Value parameters

other

A flow of elements to be combined with.

otherDefault

A default element to be used in the result tuple when the current flow is longer.

thisDefault

A default element to be used in the result tuple when the other flow is longer.

Attributes

Inherited from:
FlowOps