Skuld.Comp.ScopeEnv (skuld v0.33.1)

Copy Markdown View Source

Scope machinery carried through a computation.

Groups the elements that define what scope a computation is running in:

  • evidence — installed effect handlers
  • leave_scope — cleanup chain for scoped effects
  • transform_suspend — suspend decoration chain, also scoped
  • current_fiber_id — set when executing inside a FiberPool fiber, nil otherwise

These are installed together via scoped/2, inherited together at fiber spawn, and survive suspend/resume cycles together. They are the computation's "scope structure" — the runtime context that determines how effects are handled.

Relationship with Env

ScopeEnv is embedded in Env.scope. The Env module provides accessor functions that delegate into scope so callers don't need to reach through the nesting to read or mutate scope fields directly.

Summary

Functions

Get the current fiber ID from scope, or nil

Remove a handler for an effect signature

Get the handler for an effect signature, or nil

Get the current leave-scope handler (returns identity if nil)

Get the current transform-suspend handler (returns identity if nil)

Get all installed handler signatures

Create a fresh scope env with identity leave_scope and transform_suspend

Set the current fiber ID in scope

Install a handler for an effect signature

Install a new leave-scope handler

Install a new transform-suspend handler

Types

t()

@type t() :: %Skuld.Comp.ScopeEnv{
  current_fiber_id: term() | nil,
  evidence: %{required(Skuld.Comp.Types.sig()) => Skuld.Comp.Types.handler()},
  leave_scope: Skuld.Comp.Types.leave_scope() | nil,
  transform_suspend: Skuld.Comp.Types.transform_suspend() | nil
}

Functions

current_fiber_id(scope)

@spec current_fiber_id(t()) :: term() | nil

Get the current fiber ID from scope, or nil

delete_handler(scope, sig)

@spec delete_handler(t(), Skuld.Comp.Types.sig()) :: t()

Remove a handler for an effect signature

get_handler(scope, sig)

@spec get_handler(t(), Skuld.Comp.Types.sig()) :: Skuld.Comp.Types.handler() | nil

Get the handler for an effect signature, or nil

get_leave_scope(scope)

@spec get_leave_scope(t()) :: Skuld.Comp.Types.leave_scope()

Get the current leave-scope handler (returns identity if nil)

get_transform_suspend(scope)

@spec get_transform_suspend(t()) :: Skuld.Comp.Types.transform_suspend()

Get the current transform-suspend handler (returns identity if nil)

handler_sigs(scope)

@spec handler_sigs(t()) :: [Skuld.Comp.Types.sig()]

Get all installed handler signatures

new()

@spec new() :: t()

Create a fresh scope env with identity leave_scope and transform_suspend

put_current_fiber_id(scope, id)

@spec put_current_fiber_id(t(), term()) :: t()

Set the current fiber ID in scope

put_handler(scope, sig, handler)

@spec put_handler(t(), Skuld.Comp.Types.sig(), Skuld.Comp.Types.handler()) :: t()

Install a handler for an effect signature

with_leave_scope(scope, new_leave_scope)

@spec with_leave_scope(t(), Skuld.Comp.Types.leave_scope()) :: t()

Install a new leave-scope handler

with_transform_suspend(scope, new_transform_suspend)

@spec with_transform_suspend(t(), Skuld.Comp.Types.transform_suspend()) :: t()

Install a new transform-suspend handler