[/
 / Copyright (c) 2003-2024 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 boost_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 boost::system::error_code& ec,
      int signal_number)
  {
    ...
  }

A signal token function object:

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

A lambda as a signal token:

  signal_set.async_wait(...,
      [](const boost::system::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 boost::system::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 boost::system::error_code& ec,
      int signal_number)
  {
    ...
  }
  ...
  signal_set.async_wait(...,
      boost::bind(&my_class::signal_handler,
        this, boost::asio::placeholders::error,
        boost::asio::placeholders::signal_number));

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

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

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

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

[endsect]