Name
ranch:wait_for_connections - Wait for a specific number of connections
Description
wait_for_connections(Ref :: ranch:ref(),
Operator,
NumConns :: non_neg_integer())
-> ok
wait_for_connections(Ref :: ranch:ref(),
Operator,
NumConns :: non_neg_integer(),
Interval :: non_neg_integer())
-> ok
Operator :: '>' | '>=' | '==' | '=<' | '<'
Wait for a specific number of connections.
This function waits until the number of connections on the given listener becomes higher than, equal to or lower than the given number. It never returns otherwise.
This function can be used to gracefully shutdown a listener by first suspending the listener and then waiting for connections to terminate before finally stopping the listener.
Arguments
- Ref
The listener name.
- Operator
The operator to use for the comparison.
- NumConns
The number of connections to reach.
- Interval (1000)
Poll interval, in milliseconds.
Return value
The atom ok is always returned. It can be safely ignored.
Changelog
- 2.4:
wait_for_connections/4 is now documented.
- 1.6: Function introduced.
Examples
Wait for at least 100 connections
ranch:wait_for_connections(example, '>=', 100).
Gracefully shutdown a listener
Ref = example,
ok = ranch:suspend_listener(Ref),
ranch:wait_for_connections(Ref, '==', 0),
ok = ranch:stop_listener(Ref).
See also
ranch:stop_listener(3), ranch:suspend_listener(3), ranch:resume_listener(3), ranch(3)