pay_day_loan v0.3.0 PayDayLoan.LoadState

Keeps track of which keys are loaded, requested, and loading

Acts as a state tracker and a queue for the loader.

You shouldn’t need to call any of these functions manually but they can be useful for debugging.

Summary

Types

t()

Load states that a key can have

Functions

Returns all elements of the table

Returns true if any keys are in the :requested state

Set state to :failed

Set state to :loaded

Set state to :loading

Return load state without modifying; return nil if key is not found

Return load state; set to :requested if not loaded or loading

Set state to :requested

Return the list of requested keys

Remove a key from the load state table

Types

t()
t() :: :requested | :loading | :loaded | :failed

Load states that a key can have.

  • :requested - A load has been requested. The load worker should pick this up and set the state to :loading.
  • :loading - The load worker is in the process of loading this key.
  • :loaded - The key is loaded in cache.
  • :failed - The key attempted a load or refresh and failed.

Functions

all(ets_table_id)
all(atom) :: [{PayDayLoan.key, t}]

Returns all elements of the table

any_requested?(ets_table_id)
any_requested?(atom) :: boolean

Returns true if any keys are in the :requested state

failed(ets_table_id, keys)
failed(atom, PayDayLoan.key | [PayDayLoan.key]) ::
  :failed |
  [:failed]

Set state to :failed

loaded(ets_table_id, keys)
loaded(atom, PayDayLoan.key | [PayDayLoan.key]) ::
  :loaded |
  [:loaded]

Set state to :loaded

loading(ets_table_id, keys)
loading(atom, PayDayLoan.key | [PayDayLoan.key]) ::
  :loading |
  [:loading]

Set state to :loading

peek(ets_table_id, keys)
peek(atom, PayDayLoan.key | [PayDayLoan.key]) ::
  t |
  nil |
  [t | nil]

Return load state without modifying; return nil if key is not found

query(ets_table_id, keys)
query(atom, PayDayLoan.key | [PayDayLoan.key]) :: t | [t]

Return load state; set to :requested if not loaded or loading

request(ets_table_id, keys)
request(atom, PayDayLoan.key | [PayDayLoan.key]) ::
  :requested |
  [:requested]

Set state to :requested

requested_keys(ets_table_id)
requested_keys(atom) :: [PayDayLoan.key]

Return the list of requested keys

unload(ets_table_id, keys)
unload(atom, PayDayLoan.key | [PayDayLoan.key]) :: :ok | [:ok]

Remove a key from the load state table