Module

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

#stopRouter Source

stopRouter :: forall handle. RouterRef handle -> Effect Unit

Terminates a router by invoking the 'stop' mechanism registered when the router was first started with the handle that was returned by the initial Effect

#RouterRef Source

data RouterRef handle

Reference to a running router

  • handle is the value returned by the start mechanism of the worker

Constructors