pay_day_loan v0.5.1 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 or :reload states

Set state to :failed

Set state to :loaded

Set state to :loading

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

Set the load state to :requested if not loaded or loading, return the load state

Set the state to :reload

Return the list of keys in the :reload state, limited to limit elements

Set state to :reload_loading

Set state to :requested

Set the state to :reload if the key is loaded, set it to :request if it is not

Return the list of requested keys, limited to limit elements

Remove a key from the load state table

Types

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

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.
  • :reload - A value is available and a reload has been requested.
  • :loading - The load worker is in the process of loading this key.
  • :reload_loading - The load worker is in the process of loading this key, but it is already loaded and will not block.
  • :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 or :reload states

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]

Set the load state to :requested if not loaded or loading, return the load state

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

Set the state to :reload

reload_keys(ets_table_id, limit)
reload_keys(atom, pos_integer) :: [PayDayLoan.key]

Return the list of keys in the :reload state, limited to limit elements

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

Set state to :reload_loading

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

Set state to :requested

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

Set the state to :reload if the key is loaded, set it to :request if it is not

requested_keys(ets_table_id, limit)
requested_keys(atom, pos_integer) :: [PayDayLoan.key]

Return the list of requested keys, limited to limit elements

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

Remove a key from the load state table