Module

Effect.Aff

Package
purescript-aff
Repository
slamdata/purescript-aff

#Aff Source

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 Source

newtype Fiber a

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

Instances

#ParAff Source

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 Source

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 Source

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 Source

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

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

#launchAff_ Source

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

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

#launchSuspendedAff Source

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

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

#runAff Source

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_ Source

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 Source

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 Source

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

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

#suspendAff Source

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 Source

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 Source

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

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

#apathize Source

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

Ignores any errors.

#delay Source

delay :: Milliseconds -> Aff Unit

Pauses the running fiber.

#never Source

never :: forall a. Aff a

An async computation which does not resolve.

#finally Source

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 Source

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

Runs an effect such that it cannot be killed.

#killFiber Source

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 Source

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 Source

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 Source

bracket :: forall b a. 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 Source

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

#generalBracket Source

generalBracket :: forall b a. 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 Source

nonCanceler :: Canceler

A canceler which does not cancel anything.

#effectCanceler Source

effectCanceler :: Effect Unit -> Canceler

A canceler from an Effect action.

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 Source

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

Re-exports from Control.Parallel.Class

#sequential Source

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

Re-exports from Data.Time.Duration

Re-exports from Effect.Exception

#Error Source

data Error :: Type

The type of JavaScript errors

Instances

#message Source

message :: Error -> String

Get the error message from a JavaScript error

#error Source

error :: String -> Error

Create a JavaScript error, specifying a message