Module

Control.Monad.Aff

Package
purescript-aff
Repository
slamdata/purescript-aff

#Aff Source

data Aff :: # Effect -> Type -> Type

An Aff eff a is an asynchronous computation with effects eff. The computation may either error with an exception, or produce a result of type a. Aff effects are assembled from primitive Eff effects using makeAff or liftEff.

Instances

#Fiber Source

newtype Fiber eff a

Represents a forked computation by way of forkAff. Fibers are memoized, so their results are only computed once.

Instances

#ParAff Source

data ParAff :: # Effect -> Type -> Type

Applicative for running parallel effects. Any Aff can be coerced to a ParAff and back using the Parallel class.

Instances

#Canceler Source

newtype Canceler eff

A cancellation effect for actions run via makeAff. If a Fiber is killed, and an async action is pending, the canceler will be called to clean it up.

Constructors

Instances

#makeAff Source

makeAff :: forall eff a. ((Either Error a -> Eff eff Unit) -> Eff eff (Canceler eff)) -> Aff eff a

Constructs an Aff from low-level Eff effects using a callback. A Canceler effect should be returned to cancel the pending action. The supplied callback may be invoked only once. Subsequent invocation are ignored.

#launchAff Source

launchAff :: forall eff a. Aff eff a -> Eff eff (Fiber eff a)

Forks an Aff from an Eff context, returning the Fiber.

#launchAff_ Source

launchAff_ :: forall eff a. Aff eff a -> Eff eff Unit

Forks an Aff from an Eff context, discarding the Fiber.

#launchSuspendedAff Source

launchSuspendedAff :: forall eff a. Aff eff a -> Eff eff (Fiber eff a)

Suspends an Aff from an Eff context, returning the Fiber.

#runAff Source

runAff :: forall eff a. (Either Error a -> Eff eff Unit) -> Aff eff a -> Eff eff (Fiber eff Unit)

Forks an Aff from an Eff context and also takes a callback to run when it completes. Returns the pending Fiber.

#runAff_ Source

runAff_ :: forall eff a. (Either Error a -> Eff eff Unit) -> Aff eff a -> Eff eff Unit

Forks an Aff from an Eff context and also takes a callback to run when it completes, discarding the Fiber.

#runSuspendedAff Source

runSuspendedAff :: forall eff a. (Either Error a -> Eff eff Unit) -> Aff eff a -> Eff eff (Fiber eff Unit)

Suspends an Aff from an Eff context and also takes a callback to run when it completes. Returns the suspended Fiber.

#forkAff Source

forkAff :: forall eff a. Aff eff a -> Aff eff (Fiber eff a)

Forks am Aff from within a parent Aff context, returning the Fiber.

#suspendAff Source

suspendAff :: forall eff a. Aff eff a -> Aff eff (Fiber eff a)

Suspends an Aff from within a parent Aff context, returning the Fiber. A suspended Aff is not executed until a consumer observes the result with joinFiber.

#liftEff' Source

liftEff' :: forall eff a. Eff (exception :: EXCEPTION | eff) a -> Aff eff a

All Eff exceptions are implicitly caught within an Aff context, but standard liftEff won't remove the effect label.

#supervise Source

supervise :: forall eff a. Aff eff a -> Aff eff a

Creates a new supervision context for some Aff, guaranteeing fiber cleanup when the parent completes. Any pending fibers forked within the context will be killed and have their cancelers run.

#attempt Source

attempt :: forall eff a. Aff eff a -> Aff eff (Either Error a)

A monomorphic version of try. Catches thrown errors and lifts them into an Either.

#apathize Source

apathize :: forall eff a. Aff eff a -> Aff eff Unit

Ignores any errors.

#delay Source

delay :: forall eff. Milliseconds -> Aff eff Unit

Pauses the running fiber.

#never Source

never :: forall eff a. Aff eff a

An async computation which does not resolve.

#finally Source

finally :: forall eff a. Aff eff Unit -> Aff eff a -> Aff eff a

Runs the first effect after the second, regardless of whether it completed successfully or the fiber was cancelled.

#invincible Source

invincible :: forall eff a. Aff eff a -> Aff eff a

Runs an effect such that it cannot be killed.

#killFiber Source

killFiber :: forall eff a. Error -> Fiber eff a -> Aff eff Unit

Invokes pending cancelers in a fiber and runs cleanup effects. Blocks until the fiber has fully exited.

#joinFiber Source

joinFiber :: forall eff a. Fiber eff a -> Aff eff a

Blocks until the fiber completes, yielding the result. If the fiber throws an exception, it is rethrown in the current fiber.

#cancelWith Source

cancelWith :: forall eff a. Aff eff a -> Canceler eff -> Aff eff a

Attaches a custom Canceler to an action. If the computation is canceled, then the custom Canceler will be run afterwards.

#bracket Source

bracket :: forall eff a b. Aff eff a -> (a -> Aff eff Unit) -> (a -> Aff eff b) -> Aff eff b

Guarantees resource acquisition and cleanup. The first effect may acquire some resource, while the second will dispose of it. The third effect makes use of the resource. Disposal is always run last, regardless. Neither acquisition nor disposal may be cancelled and are guaranteed to run until they complete.

#BracketConditions Source

type BracketConditions eff a b = { completed :: b -> a -> Aff eff Unit, failed :: Error -> a -> Aff eff Unit, killed :: Error -> a -> Aff eff Unit }

#generalBracket Source

generalBracket :: forall eff a b. Aff eff a -> BracketConditions eff a b -> (a -> Aff eff b) -> Aff eff b

A general purpose bracket which lets you observe the status of the bracketed action. The bracketed action may have been killed with an exception, thrown an exception, or completed successfully.

#nonCanceler Source

nonCanceler :: forall eff. Canceler eff

A canceler which does not cancel anything.

#effCanceler Source

effCanceler :: forall eff. Eff eff Unit -> Canceler eff

A canceler from an Eff action.

Re-exports from Control.Monad.Eff.Exception

#Error

data Error :: Type

The type of JavaScript errors

Instances

  • Show Error

#message

message :: Error -> String

Get the error message from a JavaScript error

#error

error :: String -> Error

Create a JavaScript error, specifying a message

Re-exports from Control.Monad.Error.Class

#catchError Source

catchError :: forall a m e. MonadError e m => m a -> (e -> m a) -> m a

#throwError Source

throwError :: forall a m e. MonadThrow e m => e -> m a

#try Source

try :: forall e m a. MonadError e m => m a -> m (Either e a)

Return Right if the given action succeeds, Left if it throws.

Re-exports from Control.Parallel

#parallel

parallel :: forall m f. Parallel f m => m ~> f

Re-exports from Control.Parallel.Class

#sequential

sequential :: forall m f. Parallel f m => f ~> m

Re-exports from Data.Time.Duration