Module

Effect.Aff

#Aff

data Aff :: Type -> Type

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

Instances

#Fiber

newtype Fiber a

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

Instances

#ParAff

data ParAff :: Type -> Type

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

Instances

#Canceler

newtype Canceler

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

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

Constructs an Aff from low-level Effect 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

launchAff :: forall a. Aff a -> Effect (Fiber a)

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

#launchAff_

launchAff_ :: forall a. Aff a -> Effect Unit

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

#launchSuspendedAff

launchSuspendedAff :: forall a. Aff a -> Effect (Fiber a)

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

#runAff

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

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

#runAff_

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

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

#runSuspendedAff

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

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

#forkAff

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

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

#suspendAff

suspendAff :: forall a. Aff a -> Aff (Fiber 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.

#supervise

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

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

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

#apathize

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

Ignores any errors.

#delay

delay :: Milliseconds -> Aff Unit

Pauses the running fiber.

#never

never :: forall a. Aff a

An async computation which does not resolve.

#finally

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

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

#invincible

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

Runs an effect such that it cannot be killed.

#killFiber

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

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

#joinFiber

joinFiber :: Fiber ~> Aff

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

#cancelWith

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

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

#bracket

bracket :: forall a b. Aff a -> (a -> Aff Unit) -> (a -> Aff b) -> Aff 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

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

#generalBracket

generalBracket :: forall a b. Aff a -> BracketConditions a b -> (a -> Aff b) -> Aff 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

nonCanceler :: Canceler

A canceler which does not cancel anything.

#effectCanceler

effectCanceler :: Effect Unit -> Canceler

A canceler from an Effect action.

#fiberCanceler

fiberCanceler :: forall a. Fiber a -> Canceler

A canceler from a Fiber.

Re-exports from Control.Monad.Error.Class

#catchError

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

#throwError

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

#try

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

#parallel

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

#sequential

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

Re-exports from Data.Time.Duration

Re-exports from Effect.Exception

#Error

data Error :: Type

The type of JavaScript errors

Instances

#message

message :: Error -> String

Get the error message from a JavaScript error

#error

error :: String -> Error

Create a JavaScript error, specifying a message

Modules