BB.Command.ResultCache (bb v0.15.2)

Copy Markdown View Source

Caches command results for retrieval after the command process terminates.

This handles the race condition where a fast command completes before await/2 is called. The Command.Server stores its result here before terminating, and await/2 can retrieve it if the process is already dead.

Results are automatically cleaned up after a configurable TTL.

Summary

Functions

Returns a specification to start this module under a supervisor.

Fetches and removes a cached result for the given pid.

Starts the result cache.

Stores a command result, keyed by the command process pid.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

fetch_and_delete(pid)

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

Fetches and removes a cached result for the given pid.

Returns {:ok, result} if found, :error if not cached.

start_link(opts \\ [])

Starts the result cache.

store(pid, result)

@spec store(pid(), term()) :: :ok

Stores a command result, keyed by the command process pid.

Called by Command.Server in terminate/2 before the process exits.