Skuld.PageMachine (skuld_concurrency v0.41.0)

View Source

LiveView integration for FiberPool.Server — a multi-fiber page machine with bidirectional message passing.

Usage

use Skuld.PageMachine,
  tag: :checkout,
  on_yield: &handle_yield/2,
  on_complete: &handle_complete/2

Multi-spindle mode

For pages with concurrent spindles, use /3 callbacks:

on_yield: &handle_yield/3

defp handle_yield(:cart, status, socket), do: ...
defp handle_yield(:checkout, step, socket), do: ...

Event routing

By default, events go to the main fiber (the PMC tag). Use into: to route to a specific spindle:

def_pipe_event "add_to_cart", :runner, into: :cart
def_pipe_event "submit_shipping", :runner

Summary

Functions

Cancel a running page machine and all its spindles.

Resume a yielded spindle with a value.

Start a page machine in a separate FiberPool.Server process.

Functions

cancel(pid)

Cancel a running page machine and all its spindles.

def_pipe_event(event, assign_key)

(macro)

def_pipe_event(event, assign_key, list)

(macro)

def_pipe_event(event, assign_key, pattern, list)

(macro)

resume(pid, fiber_key, value)

Resume a yielded spindle with a value.

run(computation, tag)

Start a page machine in a separate FiberPool.Server process.