Pinto.MessageRouting
- Package
- erl-pinto
- Repository
- id3as/purescript-erl-pinto
This module is designed to wrap legacy APIs that send messages back to the invoking process, instead of receiving arbitrary types directly, this gives us a chance to intercept the legacy messages and lift them into an appropriate type for the current context
#startRouter Source
startRouter :: forall handle msg. Effect handle -> (handle -> Effect Unit) -> (msg -> Effect Unit) -> Effect (RouterRef handle)
Given an Effect handle
, runs that effect in a new process, returning a RouterRef for that new process
The (handle -> Effect Unit)
parameter will be invoked when the router is stopped
and the (msg -> Effect Unit)
parameter will be invoked whenever a message is received by the router
#maybeStartRouter Source
maybeStartRouter :: forall handle msg. Effect (Maybe handle) -> (handle -> Effect Unit) -> (msg -> Effect Unit) -> Effect (Maybe (RouterRef handle))
Given an Effect (Maybe handle)
, run that effect in a new process. If the effect returns Nothing, the process is terminated
else, a RouterRef handle
is returned
#stopRouterFromCallback Source
stopRouterFromCallback :: Effect Unit
Instantly terminates a router from within a callback (such as msg -> Effect Unit
) without access to the handle
Note: This should only be called from within that callback as it results in a message being sent to the current process