transient-0.4.2: Making composable programs with multithreading, events and distributed computing

Safe HaskellNone
LanguageHaskell2010

Transient.EVars

Synopsis

Documentation

data EVar a Source #

Constructors

EVar (TChan (StreamData a)) 

newEVar :: TransIO (EVar a) Source #

creates an EVar.

Evars are event vars. writeEVar trigger the execution of all the continuations associated to the readEVar of this variable (the code that is after them).

It is like the publish-subscribe pattern but without inversion of control, since a readEVar can be inserted at any place in the Transient flow.

EVars are created upstream and can be used to communicate two sub-threads of the monad. Following the Transient philosophy they do not block his own thread if used with alternative operators, unlike the IORefs and TVars. And unlike STM vars, that are composable, they wait for their respective events, while TVars execute the whole expression when any variable is modified.

The execution continues after the writeEVar when all subscribers have been executed.

Now the continuations are executed in parallel.

see https://www.fpcomplete.com/user/agocorona/publish-subscribe-variables-transient-effects-v

cleanEVar :: EVar a -> TransIO () Source #

delete al the subscriptions for an evar.

readEVar :: EVar a -> TransIO a Source #

read the EVar. It only succeed when the EVar is being updated The continuation gets registered to be executed whenever the variable is updated.

if readEVar is re-executed in any kind of loop, since each continuation is different, this will register again. The effect is that the continuation will be executed multiple times To avoid multiple registrations, use cleanEVar

writeEVar :: MonadIO m => EVar t -> t -> m () Source #

update the EVar and execute all readEVar blocks with "last in-first out" priority

lastWriteEVar :: MonadIO m => EVar t -> t -> m () Source #

write the EVar and drop all the readEVar handlers.

It is like a combination of writeEVar and cleanEVar

data Finish Source #

Constructors

Finish (EVar FinishReason) 

initFinish :: TransIO Finish Source #

initialize the event variable for finalization. all the following computations in different threads will share it it also isolate this event from other branches that may have his own finish variable

onFinish :: (FinishReason -> TransIO ()) -> TransIO () Source #

set a computation to be called when the finish event happens

finish :: FinishReason -> TransIO () Source #

trigger the event, so this closes all the resources

unFinish :: TransIO () Source #

deregister all the finalization actions. A initFinish is needed to register actions again

killOnFinish :: TransIO b -> TransIO b Source #

kill all the processes generated by the parameter when finish event occurs

checkFinalize :: StreamData a -> TransIO a Source #

trigger finish when the stream data return SDone