Once (fnord v0.8.24)

View Source

This module provides a mechanism to perform actions only once, using a unique key provided by the caller to determine whether the action has already been performed this session.

Summary

Functions

Returns a specification to start this module under a supervisor.

Checks if a key has been seen before. If the key has not been seen, it returns {:error, :not_seen}. If the key has been seen, it returns {:ok, value} where value is the value associated with the key, or true if no value was specified.

Marks a key as seen. If the key has not been seen before, it returns true and updates the internal state. If the key has already been seen, it returns false without updating the state.

Starts the agent that keeps track of seen keys.

Emits a warning (using UI.warn/1) if the message has not yet been emitted during this session.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get(key)

Checks if a key has been seen before. If the key has not been seen, it returns {:error, :not_seen}. If the key has been seen, it returns {:ok, value} where value is the value associated with the key, or true if no value was specified.

set(key, value \\ true)

Marks a key as seen. If the key has not been seen before, it returns true and updates the internal state. If the key has already been seen, it returns false without updating the state.

start_link(opts)

Starts the agent that keeps track of seen keys.

warn(msg)

Emits a warning (using UI.warn/1) if the message has not yet been emitted during this session.