CliSubprocessCore.EphemeralFiles (CliSubprocessCore v0.4.0)

Copy Markdown View Source

Owner-monitored lifecycle for temporary files a provider invocation needs on disk for the lifetime of a run.

A run may end in six different ways — a normal result, an error, an interrupt, an explicit close, the death of the process that owns the run, or a forced teardown — and a temporary file must not survive any of them. An after block covers the first four; it does not run when the owner is killed untrappably. This process therefore holds the guarantee instead of the owner: it monitors the owner and removes the owner's files when that monitor fires.

Removal is a single File.rm/1, so a forced teardown is bounded by construction.

Summary

Functions

Returns a specification to start this module under a supervisor.

Removes path now and stops tracking it. Safe to call more than once.

Starts the tracker. The application supervisor starts the singleton; tests may start isolated instances with :name.

Tracks path on behalf of owner. When owner exits for any reason the file is removed.

Whether path is currently tracked. Intended for tests and diagnostics.

Types

path()

@type path() :: Path.t()

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

release(path, server \\ __MODULE__)

@spec release(path(), GenServer.server()) :: :ok

Removes path now and stops tracking it. Safe to call more than once.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the tracker. The application supervisor starts the singleton; tests may start isolated instances with :name.

track(path, owner \\ self(), server \\ __MODULE__)

@spec track(path(), pid(), GenServer.server()) ::
  :ok | {:error, :path_already_tracked | :tracker_unavailable}

Tracks path on behalf of owner. When owner exits for any reason the file is removed.

tracked?(path, server \\ __MODULE__)

@spec tracked?(path(), GenServer.server()) :: boolean()

Whether path is currently tracked. Intended for tests and diagnostics.