[/
 / Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
 /
 / Distributed under the Boost Software License, Version 1.0. (See accompanying
 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 /]

[section:SignalToken Signal token requirements]

A signal token is a [link asio.overview.model.completion_tokens completion
token] for completion signature `void(error_code, int)`.

[heading Examples]

A free function as a signal token:

  void signal_handler(
      const asio::error_code& ec,
      int signal_number)
  {
    ...
  }

A signal token function object:

  struct signal_handler
  {
    ...
    void operator()(
        const asio::error_code& ec,
        int signal_number)
    {
      ...
    }
    ...
  };

A lambda as a signal token:

  signal_set.async_wait(...,
      [](const asio::error_code& ec,
        int signal_number)
      {
        ...
      });

A non-static class member function adapted to a signal token using
`std::bind()`:

  void my_class::signal_handler(
      const asio::error_code& ec,
      int signal_number)
  {
    ...
  }
  ...
  signal_set.async_wait(...,
      std::bind(&my_class::signal_handler,
        this, std::placeholders::_1,
        std::placeholders::_2));

A non-static class member function adapted to a signal token using
`boost::bind()`:

  void my_class::signal_handler(
      const asio::error_code& ec,
      int signal_number)
  {
    ...
  }
  ...
  signal_set.async_wait(...,
      boost::bind(&my_class::signal_handler,
        this, asio::placeholders::error,
        asio::placeholders::signal_number));

Using [link asio.reference.use_future use_future] as a signal token:

  std::future<int> f = signal_set.async_wait(..., asio::use_future);
  ...
  try
  {
    int signo = f.get();
    ...
  }
  catch (const system_error& e)
  {
    ...
  }

Using [link asio.reference.use_awaitable use_awaitable] as a signal token:

  asio::awaitable<void> my_coroutine()
  {
    try
    {
      ...
      int signo =
        co_await signal_set.async_wait(
            ..., asio::use_awaitable);
      ...
    }
    catch (const system_error& e)
    {
      ...
    }
  }

[endsect]
