Skuld.PageMachine.Spindle (skuld_concurrency v0.45.0)
View SourceNamed 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
Environment state key for %Spindle.Mappings{}.
@spec fork(atom(), Skuld.Comp.Types.computation()) :: Skuld.Comp.Types.computation()
Fork a named spindle as a FiberPool fiber.
Returns a Handle that can be used with FiberPool.await!/1.
@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
@spec with_handler(Skuld.Comp.Types.computation()) :: Skuld.Comp.Types.computation()
Install the Spindle handler. Must be installed outside FiberPool.with_handler/1
in the handler chain.