W3WS.ListenerManager (w3ws v0.2.1)
W3WS Listener Manager. Starts up and manages listeners using provided :listeners
and/or by loading listener config from the given :otp_app
.
Summary
Functions
Add a listener to the ListenerManager
Returns a specification to start this module under a supervisor.
Remove a listener from the ListenerManager
Start a listener manager
Types
Link to this type
manager_config()
@type manager_config() :: [ listeners: [W3WS.Listener.listener_config()] | nil, otp_app: atom() | nil ]
Functions
Link to this function
add_listener(pid, config)
@spec add_listener(manager :: pid(), config :: W3WS.Listener.listener_config()) :: {:ok, pid()}
Add a listener to the ListenerManager
Examples
{:ok, listener} = W3WS.ListenerManager.add_listener(
manager,
uri: "ws://localhost:8545",
subscriptions: [
[
abi_files: [path_to_abi_file],
handler: MyApp.EventHandler,
address: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
]
]
)
Link to this function
child_spec(arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
Link to this function
remove_listener(pid, listener)
Remove a listener from the ListenerManager
Examples
W3WS.ListenerManager.remove_listener(manager, listener)
Link to this function
start_link(args)
@spec start_link(manager_config()) :: {:ok, pid()}
Start a listener manager
Examples
Start a W3WS.ListenerManager
with one directly configured listener
{:ok, manager} = W3WS.ListenerManager.start_link(
listeners: [%{uri: "ws://localhost:8545"}]
)
Start a W3WS.ListenerManager
with application configuration
# in config/config.exs
config :my_app, W3WS, listeners: [
[uri: "ws://localhost:8545"]
]
# somewhere in your app
{:ok, manager} = W3WS.ListenerManager.start_link(otp_app: :my_app)
See W3WS.Listener.start_link/1
for more configuration options.