SuperWorker.Supervisor.ApiHelper (SuperWorker v0.3.6)
View SourceUtility functions for SuperWorker.Supervisor.
This module provides common utility functions used across the supervisor implementation, including:
- API call helpers
Summary
Functions
Waits for an API response matching the given reference.
Sends an API response to the caller.
Makes a synchronous API call to a target process.
Makes an asynchronous API call (fire-and-forget).
Types
@type timeout_ms() :: non_neg_integer() | :infinity
Functions
@spec api_receiver(reference(), timeout_ms()) :: any()
Waits for an API response matching the given reference.
Blocks until a message with the matching reference is received or the timeout expires.
Examples
# ... send message with ref ...
api_receiver(ref, 5000)
Sends an API response to the caller.
Examples
def handle_api({from, ref}, params) do
result = do_work(params)
api_response({from, ref}, result)
end
Makes a synchronous API call to a target process.
Sends a message in the format {api_name, {from, ref}, params} and waits
for a response with the matching reference.
Parameters
target- The pid or registered name of the target processapi- The API function name (atom)params- Parameters to pass to the APItimeout- Maximum time to wait for response in milliseconds
Examples
result = call_api(:my_supervisor, :get_worker, worker_id, 5000)
Makes an asynchronous API call (fire-and-forget).
Sends a message but does not wait for a response.
Examples
call_api_no_reply(:my_supervisor, :notify, :data_updated)