View Source Membrane.Sync (Membrane Core v0.10.2)
Sync allows to synchronize multiple processes, so that they could perform their jobs at the same time.
The main purpose for Sync is to synchronize multiple streams within a pipeline. The flow of usage goes as follows:
- A Sync process is started.
- Processes register themselves (or are registered) in the Sync, using
register/2
. Registered processes are not being synchronized till the Sync becomes active (see the next step). Each registered process is monitored and automatically unregistered upon exit. Sync can be setup to exit when all the registered processes exit by passing theempty_exit?
option tostart_link/2
. - When all processes that need to be registered are registered, the Sync can
be activated with
activate/1
function. This disables registration and enables synchronization. - Once a process needs to sync, it invokes
sync/2
, which results in blocking until all the registered processes invokesync/2
. This works only when the Sync is active - otherwise callingsync/2
returns immediately. - Once all the ready processes invoke
sync/2
, the calls return, and they become registered again. - When synchronization needs to be turned off, the Sync should be deactivated
with
deactivate/2
. This disables synchronization and enables registration again. All the calls tosync/2
return immediately.
If a process designed to work with Sync should not be synced, no_sync/0
should
be used. Then all calls to sync/2
return immediately.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Starts a Sync process linked to the current process.
Link to this section Types
@type status_t() :: :registered | :sync
@type t() :: pid() | :membrane_no_sync
Link to this section Functions
@spec activate(t()) :: :ok | {:error, :bad_activity_request}
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec deactivate(t()) :: :ok | {:error, :bad_activity_request}
@spec no_sync() :: :membrane_no_sync
Returns a Sync that always returns immediately when calling sync/2
on it.
@spec start_link([{:empty_exit?, boolean()}], GenServer.options()) :: GenServer.on_start()
Starts a Sync process linked to the current process.
options
Options
- :empty_exit? - if true, Sync automatically exits when all the registered processes exit; defaults to false