Idris2Doc : IO.Async.Core

IO.Async.Core

(source)

Reexports

importpublic Control.Monad.MCancel
importpublic Data.Linear.ELift1

Definitions

0IOToken : Type
Totality: total
Visibility: public export
0Callback : ListType->Type->Type
Totality: total
Visibility: public export
recordFiber : ListType->Type->Type
  A fiber is a series of computations that will be run
in strict sequence and will eventually terminate
with a result of type `Outcome es a`: It will either
produce a result of type `a`, an error of type `HSum es`,
or - in case it was canceled early - end with `Canceled`.

From the outside, a fiber can be observed by installing
a callback, which will be invoked as soon as the fiber has
terminated with a result.

In addition, a running fiber can be canceled, so that it
aborts all computations at soon as possible. Canceling a fiber
that has already completed is a no-op.

Totality: total
Visibility: public export
Constructor: 
MkFiber : IO1 () -> (IOToken->Callbackesa->IO1 (IO1 ())) ->Fiberesa

Projections:
.cancel_ : Fiberesa->IO1 ()
.observe_ : Fiberesa->IOToken->Callbackesa->IO1 (IO1 ())

Hint: 
Resource (Asynce) (Fiberesa)
.cancel_ : Fiberesa->IO1 ()
Totality: total
Visibility: public export
cancel_ : Fiberesa->IO1 ()
Totality: total
Visibility: public export
.observe_ : Fiberesa->IOToken->Callbackesa->IO1 (IO1 ())
Totality: total
Visibility: public export
observe_ : Fiberesa->IOToken->Callbackesa->IO1 (IO1 ())
Totality: total
Visibility: public export
dataAsync : Type->ListType->Type->Type
  Sum-type describing the computation running on a fiber.

`Async` can be thought of a powerful alternative to `IO`
that comes with error handling, capabilities for
spawning additional `Async` computations (each running
on its of `Fiber`), plus the ability for being canceled
(from the inside or from other fibers).

In order to *run* an `Async` computation, we an
`IO.Async.Loop.EventLoop`, which takes care of running
many fibers (each of which might spawn additional fibers)
concurrently. Some event loops will even offer true parallelism,
distributing the fibers to be run across several operating
system threads.

Totality: total
Visibility: public export
Constructors:
Bind : Asynceesa-> (a->Asynceesb) ->Asynceesb
  Implements bind (`>>=`)
Val : a->Asynceesa
  A pure result
Err : HSumes->Asynceesa
  An error
Sync : IO (Resultesa) ->Asynceesa
  A wrapped synchronous/blocking IO action
Cancel : Asyncees ()
  Cancels the curret fiber
OnCncl : Asynceesa->Asynce [] () ->Asynceesa
  Run the given cancel hook when cancelation is observed for `act`
UC : (IOToken->Nat->Asynceesa) ->Asynceesa
  Masks a fiber as uncanceble
This takes a function argument which will get the running fiber's
identifier token plus cancelation id in order to unmask certain
inner regions, where cancellation can again be observed.
See also `Poll`.
Attempt : Asynceesa->Asyncefs (Resultesa)
  Error handling: In case an error occured, it is wrapped in
a `Left`, while a successful result is wrapped in a `Right`.
Note, that we do not handle the `Canceled` case: Cancellation
cannot be undone. In can be temporarily masked using `UC`, but
after that, it will be observed as soon as possible.
Env : Asynceese
  Returns the context currently handling this fiber, giving us access
to functionality specific to the running event loop.
Self : AsynceesIOToken
  Returns the current fiber's unique identifier
Cede : Asyncees ()
  Cedes control to the execution context
Fibers are auto-ceded after a predefined number of evaluation steps
to make sure other fibers get a chance to run even when the event loop
is single-threaded. In addition, a fiber can make room for other
fibers by invoking `cede` at strategic points.
Start : Asynceesa->Asyncefs (Fiberesa)
  Runs the given computation concurrently to this one returning a
`Fiber` representing the runnign computation.
Asnc : ((Resultesa->IO1 ()) ->IO1 (IO1 ())) ->Asynceesa
  The asynchronous primitive. This allows us to register callbacks
and await their invocation, thus blocking the current fiber until
a result is ready. Being able to treat this as a regular
IO-like computation is one of the main reasons why `Async` is such
a powerful abstraction.

The `IO1 ()` returned after installing a callback will be treated
as a cancellation hook: It will be invoked if the current
computation is canceled and cancellation can currently be observed.

We use this data constructor whenever we'd like to wait for a
result to be ready at a later time such as a timer, input from
a pipe or socket, or data available from standard input.
APoll : IOToken->Nat->Asynceesa->Asynceesa
  Temporarily undo a layer of uncancelability. See also `UC`.

Hints:
ELift1World (Asynce)
HasIO (Asyncees)
MCancel (Asynce)
MErr (Asynce)
Resource (Asynce) (Fiberesa)
terminal : Resultesa->Asynceesa
  Lifts a pure `Result` into `Async`.

Totality: total
Visibility: export
sync : IO (Resultesa) ->Asynceesa
  Lifts an effectful `Result` into `Async`.

Totality: total
Visibility: export
primAsync : ((Resultesa->IO1 ()) ->IO1 (IO1 ())) ->Asynceesa
  Asynchronous FFI: Wraps a callback handler into `Async`.

The `IO1 ()` action returned after registering the callback will
be used for cancelation and cleanup.

Totality: total
Visibility: export
start : Asynceesa->Asyncefs (Fiberesa)
  Starts a new fiber, running it concurrently to the current one

Totality: total
Visibility: export
cede : Asyncees ()
  Cedes control back to the execution context.

Totality: total
Visibility: export
env : Asynceese
  Returns the environment provided by the event loop this
fiber is currently running in.

Totality: total
Visibility: export
self : AsynceesIOToken
  Returns this fiber's unique identifier.

Totality: total
Visibility: export