CompletionHandler.qbk 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. [/
  2. / Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  3. /
  4. / Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. /]
  7. [section:CompletionHandler Completion handler requirements]
  8. A completion handler must meet the requirements for a [link
  9. boost_asio.reference.Handler handler]. A value `h` of a completion handler
  10. class should work correctly in the expression `h()`.
  11. [heading Examples]
  12. A free function as a completion handler:
  13. void completion_handler()
  14. {
  15. ...
  16. }
  17. A completion handler function object:
  18. struct completion_handler
  19. {
  20. ...
  21. void operator()()
  22. {
  23. ...
  24. }
  25. ...
  26. };
  27. A lambda as a completion handler:
  28. my_io_service.post(
  29. []()
  30. {
  31. ...
  32. });
  33. A non-static class member function adapted to a completion handler using
  34. `std::bind()`:
  35. void my_class::completion_handler()
  36. {
  37. ...
  38. }
  39. ...
  40. my_io_service.post(std::bind(&my_class::completion_handler, this));
  41. A non-static class member function adapted to a completion handler using
  42. `boost::bind()`:
  43. void my_class::completion_handler()
  44. {
  45. ...
  46. }
  47. ...
  48. my_io_service.post(boost::bind(&my_class::completion_handler, this));
  49. [endsect]