LEARN VOID

Topic subscriptions

Deliver a typed notification to a subscriber and disconnect it by handle.

channels.voidDownload source
use channel

func entry(count: i32) -> i32:
    var updates = channel.router<i32>()
    var displayed: i32 = 0
    var token = updates.subscribe("stock", func(const quantity: i32):
        displayed = quantity
    )
    updates.emit("stock", count)
    updates.unsubscribe(token)
    return displayed
Input 9Expected result 9

Send one update

A channel.router<i32> delivers one payload type. A callback captures the local display value. Emitting a count on the matching topic updates it before emit returns.

Own the subscription

Store the subscription returned by subscribe, then pass that token to the same router to unsubscribe. Dropping a token alone does not disconnect its handler. clear() removes registrations and the router can be reused.

Deliver on the owning thread

Delivery is synchronous in registration order. A router is managed, so assignments share subscriptions. Use it on its owning application thread. Worker communication requires a different ownership model.

Continue learning with Events · Closures.