Channel primitives for connecting external event sources to Flow.
Use connect when you have both a subscription source and a command to
kick off the channel, or join when subscriptions alone are enough.
Then consume events with Flow.await, Flow.subscribe, or Flow.subscribeWhile.
Build a channel from a subscription source and a command that opens or attaches it. The command is fired once when the channel is first awaited.
-- Port declarations:
-- port onMessage : (String -> msg) -> Sub msg
-- port subscribe : String -> Cmd msg
myChannel : Channel Model String
myChannel =
Flow.Channel.connect
(\callback -> Ports.onMessage callback)
(\_ -> Ports.subscribe "myTopic")Build a channel from a subscription source when no startup command is needed.
-- Port declaration:
-- port onKeyDown : (String -> msg) -> Sub msg
keyChannel : Channel Model String
keyChannel =
Flow.Channel.join (\callback -> Ports.onKeyDown callback)Filter events for a channel. Only events for which the predicate returns
True are forwarded; others are silently dropped.
The predicate receives the internal channel key and the event payload. In most cases you only need the payload:
Flow.Channel.filter (\_ msg -> msg /= "") myChannelFire the channel's setup command and suspend until the first value arrives.
The callback decides what to do next: Just flow to continue, Nothing to
close the subscription.
This is the low-level primitive that Flow.await and Flow.subscribe are
built on. Prefer those unless you need custom continuation logic.
An opaque handle describing how to connect an external event source to a
Flowpipeline. Build one withconnectorjoin, then pass it toFlow.awaitorFlow.subscribe.