Module

Control.Monad.Aff

Package
purescript-aff
Repository
slamdata/purescript-aff

#Aff Source

data Aff :: Row 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

#ParAff Source

data ParAff :: Row Effect -> Type -> Type

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

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

#killFiber Source

killFiber :: forall a eff. 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 a eff. 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.

#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

#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.

#launchAff Source

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

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

#launchAff_ Source

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

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

#launchSuspendedAff Source

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

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

#runAff Source

runAff :: forall a eff. (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 a eff. (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 a eff. (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 a eff. Aff eff a -> Aff eff (Fiber eff a)

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

#suspendAff Source

suspendAff :: forall a eff. 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.

#delay Source

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

Pauses the running fiber.

#never Source

never :: forall a eff. Aff eff a

An async computation which does not resolve.

#liftEff' Source

liftEff' :: forall a eff. 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.

#attempt Source

attempt :: forall a eff. 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 a eff. Aff eff a -> Aff eff Unit

Ignores any errors.

#finally Source

finally :: forall a eff. 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 a eff. Aff eff a -> Aff eff a

Runs an effect such that it cannot be killed.

#cancelWith Source

cancelWith :: forall a eff. 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 b a eff. 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.

#supervise Source

supervise :: forall a eff. 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.

#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 b a eff. 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.

#makeAff Source

makeAff :: forall a eff. ((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.

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 e m a. MonadError e m => m a -> (e -> m a) -> m a

#throwError Source

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

#try Source

try :: forall a m e. 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 f m. Parallel f m => m ~> f

Re-exports from Control.Parallel.Class

#sequential

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

Re-exports from Data.Time.Duration

#Milliseconds

newtype Milliseconds

A duration measured in milliseconds.

Constructors

  • Milliseconds Number

Instances

  • Newtype Milliseconds _
  • Generic Milliseconds
  • Eq Milliseconds
  • Ord Milliseconds
  • Semiring Milliseconds
  • Ring Milliseconds
  • Show Milliseconds
  • Duration Milliseconds