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:
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}")
}Output
[1, 2]
pub(api) fn subscribeOf<T: Serializable>(h: i64, group: str, key: bytes, hasKey: i64, from: TopicStart?, lease: Duration) -> stream<T, TopicError> dbThread safety. a subscription belongs to the task that reads it; members of a group share the work through the store, not memory.
Since. 1.0.0-beta
Parameters
| Name | Type |
|---|---|
h | i64 |
group | str |
key | bytes |
hasKey | i64 |
from | TopicStart? |
lease | Duration |
Returns
stream<T, TopicError>
Effects
db
Defined in: std/topic/topic.oxl:587