Skuld.PageMachine.Spindle (skuld_concurrency v0.47.0)

View Source

Named concurrent sub-computations (spindles) that run as fibers within a FiberPool. Each spindle is identified by an atom key and communicates results through auto-tagged yields.

Usage

use Skuld.Syntax

comp do
  checkout <- Spindle.fork(:checkout, MyApp.CheckoutFlow.flow(product))

  # Main spindle continues...
  filters <- Yield.yield(:search)
  {:ok, results} <- MyApp.ProductCatalog.search(filters)
  Yield.yield({:results, results})
end
|> Spindle.with_handler()
|> FiberYield.with_handler()
|> FiberPool.with_handler()
|> Comp.run()

Summary

Functions

Environment state key for %Spindle.Mappings{}.

Fork a named spindle as a FiberPool fiber.

Fire-and-forget notification to the PageMachine caller.

Install the Spindle handler. Must be installed outside FiberPool.with_handler/1 in the handler chain.

Functions

env_key()

Environment state key for %Spindle.Mappings{}.

fork(key, computation)

Fork a named spindle as a FiberPool fiber.

Returns a Handle that can be used with FiberPool.await!/1.

notify(value)

@spec notify(term()) :: Skuld.Comp.Types.computation()

Fire-and-forget notification to the PageMachine caller.

Surfaces value to the caller (e.g., the LiveView) without pausing the spindle. The fiber continues immediately on the next scheduler round. Returns nil on resume.

Example

comp do
  Spindle.notify(:purchase_selected)
  # spindle continues immediately, no Yield.yield pause
  {:ok, results} <- MyApp.Catalog.search(filters)
  ...
end

with_handler(computation)

Install the Spindle handler. Must be installed outside FiberPool.with_handler/1 in the handler chain.