ranch.wait_for_connections.asciidoc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. = ranch:wait_for_connections(3)
  2. == Name
  3. ranch:wait_for_connections - Wait for a specific number of connections
  4. == Description
  5. [source,erlang]
  6. ----
  7. wait_for_connections(Ref :: ranch:ref(),
  8. Operator,
  9. NumConns :: non_neg_integer())
  10. -> ok
  11. Operator :: '>' | '>=' | '==' | '=<' | '<'
  12. ----
  13. Wait for a specific number of connections.
  14. This function waits until the number of connections on the
  15. given listener becomes higher than, equal to or lower than
  16. the given number. It never returns otherwise.
  17. This function can be used to gracefully shutdown a listener
  18. by first suspending the listener and then waiting for
  19. connections to terminate before finally stopping the listener.
  20. // @todo The suspend/wait/stop pattern should be tested.
  21. == Arguments
  22. Ref::
  23. The listener name.
  24. Operator::
  25. The operator to use for the comparison.
  26. NumConns::
  27. The number of connections to reach.
  28. == Return value
  29. The atom `ok` is always returned. It can be safely ignored.
  30. == Changelog
  31. * *1.6*: Function introduced.
  32. == Examples
  33. .Wait for at least 100 connections
  34. [source,erlang]
  35. ----
  36. ranch:wait_for_connections(example, '>=', 100).
  37. ----
  38. .Gracefully shutdown a listener
  39. [source,erlang]
  40. ----
  41. Ref = example,
  42. ok = ranch:suspend_listener(Ref),
  43. ranch:wait_for_connections(Ref, '==', 0),
  44. ok = ranch:stop_listener(Ref).
  45. ----
  46. == See also
  47. link:man:ranch:stop_listener(3)[ranch:stop_listener(3)],
  48. link:man:ranch:suspend_listener(3)[ranch:suspend_listener(3)],
  49. link:man:ranch:resume_listener(3)[ranch:resume_listener(3)],
  50. link:man:ranch(3)[ranch(3)]