OxL Справочник OxL
РусскийEnglish

data stream

Asynchronous sequence of T that ends normally or with one error E; source for for await (§10.3, D-2600..).

Example:

oxl✓ проверяется в CI
fn countdown(n: i64) -> stream<i64> {
  var i = n
  while i > 0 {
    yield i
    i -= 1
  }
}

fn main() io {
  for await x in countdown(3) {
    print("{x}")
  }
}
Вывод
3
2
1
@builtin("stream") pub(api) data stream<T, E = never>

Потокобезопасность. a stream is consumed by one task.

С версии. 1.0.0-beta

Методы

pull() -> Pulled<T, E>
Waits for the next element (a suspension point and cancellation point).
pullWithin(d: Duration) -> Pulled<T, E>
Like pull, but gives up after d with Timeout.
first() -> T | E | none
The next element, the error that ended the stream, or none at its end (await sub.first() in [С V.5], D-6109).
lagged() -> u64
Elements dropped for this subscription by Broadcast with .DropOldest (0 for every other stream).
offset() -> u64
Offset of the element delivered last
seek(n: u64)
Continues at offset n before the first pull
resumeFrom(n: u64) -> stream<T, E>
resumeFrom(n): the same stream, continuing at offset n (§10.3).
withOffsets() -> stream<(u64, T), E>
Every element with its offset
results() -> stream<T | E>
The error of the stream as one more element

Определено в: std/core/types.oxl:443

См. также