mirror of
https://github.com/boostorg/asio.git
synced 2026-01-19 04:02:09 +00:00
Add default completion token to 1-arg overloads of dispatch, post and defer.
This commit is contained in:
@@ -80,8 +80,8 @@ namespace asio {
|
||||
* @par Completion Signature
|
||||
* @code void() @endcode
|
||||
*/
|
||||
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) NullaryToken>
|
||||
inline auto defer(NullaryToken&& token)
|
||||
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) NullaryToken = deferred_t>
|
||||
inline auto defer(NullaryToken&& token = deferred_t())
|
||||
-> decltype(
|
||||
async_initiate<NullaryToken, void()>(
|
||||
declval<detail::initiate_defer>(), token))
|
||||
|
||||
@@ -70,8 +70,8 @@ namespace asio {
|
||||
* @par Completion Signature
|
||||
* @code void() @endcode
|
||||
*/
|
||||
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) NullaryToken>
|
||||
inline auto dispatch(NullaryToken&& token)
|
||||
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) NullaryToken = deferred_t>
|
||||
inline auto dispatch(NullaryToken&& token = deferred_t())
|
||||
-> decltype(
|
||||
async_initiate<NullaryToken, void()>(
|
||||
declval<detail::initiate_dispatch>(), token))
|
||||
|
||||
@@ -78,8 +78,8 @@ namespace asio {
|
||||
* @par Completion Signature
|
||||
* @code void() @endcode
|
||||
*/
|
||||
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) NullaryToken>
|
||||
inline auto post(NullaryToken&& token)
|
||||
template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) NullaryToken = deferred_t>
|
||||
inline auto post(NullaryToken&& token = deferred_t())
|
||||
-> decltype(
|
||||
async_initiate<NullaryToken, void()>(
|
||||
declval<detail::initiate_post>(), token))
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
// Test that header file is self-contained.
|
||||
#include <boost/asio/defer.hpp>
|
||||
|
||||
#include <boost/asio/bind_executor.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include "unit_test.hpp"
|
||||
|
||||
@@ -95,6 +96,22 @@ void move_only_result_handler(
|
||||
*result_out = result_in.value();
|
||||
}
|
||||
|
||||
void defer_no_args_test()
|
||||
{
|
||||
io_context ctx(1);
|
||||
|
||||
int handler_count = 0;
|
||||
boost::asio::defer(boost::asio::deferred)(
|
||||
boost::asio::bind_executor(ctx,
|
||||
bindns::bind(void_handler, &handler_count)));
|
||||
|
||||
BOOST_ASIO_CHECK(handler_count == 0);
|
||||
|
||||
ctx.run();
|
||||
|
||||
BOOST_ASIO_CHECK(handler_count == 1);
|
||||
}
|
||||
|
||||
void defer_function_test()
|
||||
{
|
||||
io_context ctx(1);
|
||||
@@ -229,5 +246,6 @@ void defer_function_test()
|
||||
BOOST_ASIO_TEST_SUITE
|
||||
(
|
||||
"defer",
|
||||
BOOST_ASIO_TEST_CASE(defer_no_args_test)
|
||||
BOOST_ASIO_TEST_CASE(defer_function_test)
|
||||
)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
// Test that header file is self-contained.
|
||||
#include <boost/asio/dispatch.hpp>
|
||||
|
||||
#include <boost/asio/bind_executor.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include "unit_test.hpp"
|
||||
|
||||
@@ -95,6 +96,22 @@ void move_only_result_handler(
|
||||
*result_out = result_in.value();
|
||||
}
|
||||
|
||||
void dispatch_no_args_test()
|
||||
{
|
||||
io_context ctx(1);
|
||||
|
||||
int handler_count = 0;
|
||||
boost::asio::dispatch(boost::asio::deferred)(
|
||||
boost::asio::bind_executor(ctx,
|
||||
bindns::bind(void_handler, &handler_count)));
|
||||
|
||||
BOOST_ASIO_CHECK(handler_count == 0);
|
||||
|
||||
ctx.run();
|
||||
|
||||
BOOST_ASIO_CHECK(handler_count == 1);
|
||||
}
|
||||
|
||||
void dispatch_function_test()
|
||||
{
|
||||
io_context ctx(1);
|
||||
@@ -229,5 +246,6 @@ void dispatch_function_test()
|
||||
BOOST_ASIO_TEST_SUITE
|
||||
(
|
||||
"dispatch",
|
||||
BOOST_ASIO_TEST_CASE(dispatch_no_args_test)
|
||||
BOOST_ASIO_TEST_CASE(dispatch_function_test)
|
||||
)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
// Test that header file is self-contained.
|
||||
#include <boost/asio/post.hpp>
|
||||
|
||||
#include <boost/asio/bind_executor.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include "unit_test.hpp"
|
||||
|
||||
@@ -95,6 +96,22 @@ void move_only_result_handler(
|
||||
*result_out = result_in.value();
|
||||
}
|
||||
|
||||
void post_no_args_test()
|
||||
{
|
||||
io_context ctx(1);
|
||||
|
||||
int handler_count = 0;
|
||||
boost::asio::post(boost::asio::deferred)(
|
||||
boost::asio::bind_executor(ctx,
|
||||
bindns::bind(void_handler, &handler_count)));
|
||||
|
||||
BOOST_ASIO_CHECK(handler_count == 0);
|
||||
|
||||
ctx.run();
|
||||
|
||||
BOOST_ASIO_CHECK(handler_count == 1);
|
||||
}
|
||||
|
||||
void post_function_test()
|
||||
{
|
||||
io_context ctx(1);
|
||||
@@ -229,5 +246,6 @@ void post_function_test()
|
||||
BOOST_ASIO_TEST_SUITE
|
||||
(
|
||||
"post",
|
||||
BOOST_ASIO_TEST_CASE(post_no_args_test)
|
||||
BOOST_ASIO_TEST_CASE(post_function_test)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user