SuperCache.Sup (SuperCache v1.3.0)

Copy Markdown View Source

Dynamic supervisor for user-spawned workers in SuperCache.

This module provides a DynamicSupervisor that allows runtime creation and management of child processes. It is primarily used for starting buffer streams and other dynamically allocated resources.

Example

# Start a single worker
{:ok, pid} = SuperCache.Sup.start_worker({MyWorker, []})

# Start multiple workers
workers = [{Worker1, []}, {Worker2, []}]
results = SuperCache.Sup.start_workers(workers)

Summary

Functions

Returns a specification to start this module under a supervisor.

Starts the dynamic supervisor linked to the current process.

Starts a single child specification under this supervisor.

Starts a list of child specifications under this supervisor.

Terminates a child process identified by pid or name.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(init_arg)

@spec start_link(keyword()) :: :ignore | {:error, any()} | {:ok, pid()}

Starts the dynamic supervisor linked to the current process.

The supervisor is registered under the name SuperCache.Sup.

start_worker(spec)

@spec start_worker(Supervisor.child_spec() | {module(), term()} | module()) ::
  {:ok, pid()} | {:error, term()}

Starts a single child specification under this supervisor.

Returns {:ok, pid} on success or {:error, reason} on failure.

start_workers(workers)

@spec start_workers([Supervisor.child_spec() | {module(), term()} | module()]) :: [
  ok: pid(),
  error: term()
]

Starts a list of child specifications under this supervisor.

Returns a list of {:ok, pid} or {:error, reason} tuples corresponding to each child specification.

Examples

SuperCache.Sup.start_workers([{MyWorker, arg1}, {OtherWorker, arg2}])
# => [{:ok, #PID<0.100.0>}, {:ok, #PID<0.101.0>}]

stop_worker(pid_or_name)

@spec stop_worker(pid() | atom()) :: :ok | {:error, term()}

Terminates a child process identified by pid or name.

terminate(reason, state)