MingaEditor.EffectScheduler.Lane (Minga v0.1.0)

Copy Markdown View Source

Pure scheduling transitions for one effect resource lane.

Summary

Functions

Returns true when a running or queued request matches.

Admits a request into a lane without performing effects.

Cancels all matching requests in this lane.

Cancels one request by id. Running work remains current until its candidate is finalized.

Releases the matching current request without promoting queued work.

Promotes the next queued request when a lane has no current request.

Builds an empty resource lane for a stable policy.

Finds the request id for a semantic operation id.

Types

action()

@type action() ::
  {:start, MingaEditor.Effect.Request.t()}
  | {:stop, MingaEditor.Effect.Request.t()}
  | {:candidate, MingaEditor.Effect.Request.t(), {:canceled, cancel_reason()}}
  | {:terminal, MingaEditor.Effect.Request.t(), {:canceled, cancel_reason()}}
  | {:terminal, MingaEditor.Effect.Request.t(), {:stale, cancel_reason()}}
  | {:queue,
     [{MingaEditor.Effect.Request.t(), pos_integer(), non_neg_integer()}]}

admission()

@type admission() ::
  {:ok, MingaEditor.Effect.Request.id(), :running | :queued}
  | {:error, admission_error()}

admission_error()

@type admission_error() :: :policy_mismatch | :queue_full | :scheduler_full

cancel_reason()

@type cancel_reason() :: term()

t()

@type t() :: %MingaEditor.EffectScheduler.Lane{
  policy: MingaEditor.Effect.Policy.t(),
  queue: :queue.queue(MingaEditor.Effect.Request.t()),
  running: MingaEditor.Effect.Request.t() | nil
}

Functions

active?(lane, match?)

@spec active?(t(), (MingaEditor.Effect.Request.t() -> boolean())) :: boolean()

Returns true when a running or queued request matches.

admit(lane, request, capacity?)

@spec admit(t() | nil, MingaEditor.Effect.Request.t(), boolean()) ::
  {admission(), t() | nil, [action()]}

Admits a request into a lane without performing effects.

cancel_matching(lane, match?, reason)

@spec cancel_matching(t(), (MingaEditor.Effect.Request.t() -> boolean()), term()) ::
  {t(), [action()], boolean()}

Cancels all matching requests in this lane.

cancel_request(lane, request_id)

@spec cancel_request(t(), MingaEditor.Effect.Request.id()) ::
  {:ok, t(), [action()]} | :not_found

Cancels one request by id. Running work remains current until its candidate is finalized.

finalize_current(lane, request)

@spec finalize_current(t(), MingaEditor.Effect.Request.t()) ::
  {:empty, [action()]} | {t(), [action()]}

Releases the matching current request without promoting queued work.

finish_current(lane)

@spec finish_current(t()) :: {:empty, [action()]} | {t(), [action()]}

Promotes the next queued request when a lane has no current request.

new(policy)

@spec new(MingaEditor.Effect.Policy.t()) :: t()

Builds an empty resource lane for a stable policy.

request_id_for_operation(lane, operation_id)

@spec request_id_for_operation(t(), MingaEditor.State.Operation.id()) ::
  MingaEditor.Effect.Request.id() | nil

Finds the request id for a semantic operation id.