Module

Effect.AVar

Package
purescript-avar
Repository
purescript-contrib/purescript-avar

#AVar Source

data AVar :: Type -> Type

#AVarCallback Source

#AVarStatus Source

data AVarStatus a

Constructors

#new Source

new :: forall a. a -> Effect (AVar a)

Creates a fresh AVar with an initial value.

#empty Source

empty :: forall a. Effect (AVar a)

Creates a new empty AVar.

#take Source

take :: forall a. AVar a -> AVarCallback a -> Effect (Effect Unit)

Takes the AVar value, leaving it empty. If the AVar is already empty, the callback will be queued until the AVar is filled. Multiple takes will resolve in order as the AVar fills. Returns an effect which will remove the callback from the pending queue.

#tryTake Source

tryTake :: forall a. AVar a -> Effect (Maybe a)

Attempts to synchronously take an AVar value, leaving it empty. If the AVar is empty, this will return Nothing.

#put Source

put :: forall a. a -> AVar a -> AVarCallback Unit -> Effect (Effect Unit)

Sets the value of the AVar. If the AVar is already filled, it will be queued until the value is emptied. Multiple puts will resolve in order as the AVar becomes available. Returns an effect which will remove the callback from the pending queue.

#tryPut Source

tryPut :: forall a. a -> AVar a -> Effect Boolean

Attempts to synchronously fill an AVar. If the AVar is already filled, this will do nothing. Returns true or false depending on if it succeeded.

#read Source

read :: forall a. AVar a -> AVarCallback a -> Effect (Effect Unit)

Reads the AVar value. Unlike take, this will not leave the AVar empty. If the AVar is empty, this will queue until it is filled. Multiple reads will resolve at the same time, as soon as possible.

#tryRead Source

tryRead :: forall a. AVar a -> Effect (Maybe a)

Attempts to synchronously read an AVar. If the AVar is empty, this will return Nothing.

#kill Source

kill :: forall a. Error -> AVar a -> Effect Unit

Kills the AVar with an exception. All pending and future actions will resolve immediately with the provided exception.

#status Source

status :: forall a. AVar a -> Effect (AVarStatus a)

Synchronously checks the status of an AVar.

#isEmpty Source

isEmpty :: forall a. AVarStatus a -> Boolean

#isFilled Source

isFilled :: forall a. AVarStatus a -> Boolean

#isKilled Source

isKilled :: forall a. AVarStatus a -> Boolean