Skuld.Comp.InternalSuspend (skuld v0.2.3)

View Source

Internal suspension for Env-aware code.

Unlike Comp.ExternalSuspend (which closes over env for external callbacks), this suspension receives env at resume time, allowing callers to supply an updated env when resuming.

Two Kinds of Suspension

External suspension (Comp.ExternalSuspend):

  • resume :: (val) -> {result, env}
  • Closes over env at suspension point
  • For passing to external code that doesn't understand Skuld's env threading

Internal suspension (Comp.InternalSuspend):

  • resume :: (val, env) -> {result, env}
  • Does NOT close over env - receives it at resume time
  • For schedulers/handlers that need to thread updated env through suspensions

Payload Types

The payload field contains a struct that identifies the kind of suspension:

  • Batch - batchable operations (DB fetches, etc.)
  • Channel - channel put/take operations
  • Await - fiber await operations

Summary

Functions

Create an await-all suspension.

Create an await-any suspension.

Create an await-one suspension.

Create a batch operation suspension.

Create a channel put suspension.

Create a channel take suspension.

Types

payload()

@type payload() ::
  Skuld.Comp.InternalSuspend.Batch.t()
  | Skuld.Comp.InternalSuspend.Channel.t()
  | Skuld.Comp.InternalSuspend.Await.t()

t()

@type t() :: %Skuld.Comp.InternalSuspend{
  payload: payload(),
  resume: (term(), Skuld.Comp.Types.env() -> {term(), Skuld.Comp.Types.env()})
}

Functions

await_all(handles, resume)

@spec await_all([Skuld.Fiber.Handle.t()], Skuld.Comp.Types.k()) :: t()

Create an await-all suspension.

await_any(handles, resume)

@spec await_any([Skuld.Fiber.Handle.t()], Skuld.Comp.Types.k()) :: t()

Create an await-any suspension.

await_one(handle, resume, opts \\ [])

@spec await_one(Skuld.Fiber.Handle.t(), Skuld.Comp.Types.k(), keyword()) :: t()

Create an await-one suspension.

batch(op, request_id, resume)

@spec batch(term(), reference(), Skuld.Comp.Types.k()) :: t()

Create a batch operation suspension.

channel_put(channel_id, item, resume)

@spec channel_put(reference(), term(), Skuld.Comp.Types.k()) :: t()

Create a channel put suspension.

channel_take(channel_id, resume)

@spec channel_take(reference(), Skuld.Comp.Types.k()) :: t()

Create a channel take suspension.