1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
= ranch:wait_for_connections(3)
== Name
ranch:wait_for_connections - Wait for a specific number of connections
== Description
[source,erlang]
----
wait_for_connections(Ref :: ranch:ref(),
Operator,
NumConns :: 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.
// @todo The suspend/wait/stop pattern should be tested.
== Arguments
Ref::
The listener name.
Operator::
The operator to use for the comparison.
NumConns::
The number of connections to reach.
== Return value
The atom `ok` is always returned. It can be safely ignored.
== Changelog
* *1.6*: Function introduced.
== Examples
.Wait for at least 100 connections
[source,erlang]
----
ranch:wait_for_connections(example, '>=', 100).
----
.Gracefully shutdown a listener
[source,erlang]
----
Ref = example,
ok = ranch:suspend_listener(Ref),
ranch:wait_for_connections(Ref, '==', 0),
ok = ranch:stop_listener(Ref).
----
== See also
link:man:ranch:stop_listener(3)[ranch:stop_listener(3)],
link:man:ranch:suspend_listener(3)[ranch:suspend_listener(3)],
link:man:ranch:resume_listener(3)[ranch:resume_listener(3)],
link:man:ranch(3)[ranch(3)]
|