Skuld.Comp.Cancelled (skuld v0.1.26)
View SourceSentinel indicating a computation was cancelled.
Like Throw, Cancelled goes through the leave_scope chain, allowing
effects to clean up resources (close connections, release locks, etc.)
when a computation is cancelled.
Usage
When cancelling a suspended computation, use Skuld.Comp.cancel/2:
# Computation yielded a Suspend
{%Suspend{} = suspend, env} = Comp.run(my_comp)
# Cancel it (invokes leave_scope chain for cleanup)
{%Cancelled{reason: :user_cancelled}, final_env} =
Comp.cancel(suspend, env, :user_cancelled)Effect Cleanup
Effects can detect cancellation in their leave_scope handler:
def my_leave_scope(result, env) do
case result do
%Cancelled{reason: reason} ->
cleanup_resources(reason)
{result, env}
_ ->
{result, env}
end
end
Summary
Types
@type t() :: %Skuld.Comp.Cancelled{reason: term()}