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

fn subscribeOf

Opens the subscription NOW (so .Latest means "from this call", not "from the first pull") and returns the stream that reads it.

Example:

oxl✓ проверяется в CI
data Job { id: i64 }

topic Jobs: Job

cluster demo {
  role store { journal }
}

fn main() -> () | TopicError io, db, time {
  Jobs.publish(Job{ id: 1 })?
  Jobs.publish(Job{ id: 2 })?
  var s = Jobs.subscribe(group: "workers")
  var got: List<i64> = []
  loop {
    match s.pullWithin(300ms) {
      .Item(value: j) => got.push(j.id)
      _ => break
    }
  }
  print("{got}")
}
Вывод
[1, 2]
pub(api) fn subscribeOf<T: Serializable>(h: i64, group: str, key: bytes, hasKey: i64, from: TopicStart?, lease: Duration) -> stream<T, TopicError>  db

Потокобезопасность. a subscription belongs to the task that reads it; members of a group share the work through the store, not memory.

С версии. 1.0.0-beta

Параметры

ИмяТип
hi64
groupstr
keybytes
hasKeyi64
fromTopicStart?
leaseDuration

Возвращает

stream<T, TopicError>

Эффекты

db

Определено в: std/topic/topic.oxl:587

См. также