feat add asio
Some checks failed
linux-x64-gcc / linux-gcc (Release) (push) Failing after 42s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Failing after 57s
linux-x64-gcc / linux-gcc (Debug) (push) Failing after 59s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Failing after 1m21s
linux-arm-gcc / linux-gcc-armhf (push) Failing after 1m29s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Failing after 1m32s
Some checks failed
linux-x64-gcc / linux-gcc (Release) (push) Failing after 42s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Failing after 57s
linux-x64-gcc / linux-gcc (Debug) (push) Failing after 59s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Failing after 1m21s
linux-arm-gcc / linux-gcc-armhf (push) Failing after 1m29s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Failing after 1m32s
This commit is contained in:
parent
de11bddde9
commit
302b944081
@ -201,6 +201,7 @@ if(SLED_BUILD_TESTS)
|
|||||||
sled_add_test(NAME sled_event_bus_test SRCS
|
sled_add_test(NAME sled_event_bus_test SRCS
|
||||||
src/sled/event_bus/event_bus_test.cc)
|
src/sled/event_bus/event_bus_test.cc)
|
||||||
sled_add_test(NAME sled_lua_test SRCS tests/lua_test.cc)
|
sled_add_test(NAME sled_lua_test SRCS tests/lua_test.cc)
|
||||||
|
sled_add_test(NAME sled_asio_test SRCS tests/asio_test.cc)
|
||||||
sled_add_test(NAME sled_move_on_copy_test SRCS
|
sled_add_test(NAME sled_move_on_copy_test SRCS
|
||||||
src/sled/utility/move_on_copy_test.cc)
|
src/sled/utility/move_on_copy_test.cc)
|
||||||
sled_add_test(NAME sled_symbolize_test SRCS
|
sled_add_test(NAME sled_symbolize_test SRCS
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#define SLED_SLED_H
|
#define SLED_SLED_H
|
||||||
|
|
||||||
// thrid_party
|
// thrid_party
|
||||||
|
#include <asio.hpp>
|
||||||
#include "rx.h"
|
#include "rx.h"
|
||||||
#include "sled/nonstd/cxxopts.h"
|
#include "sled/nonstd/cxxopts.h"
|
||||||
#include "sled/nonstd/expected.h"
|
#include "sled/nonstd/expected.h"
|
||||||
|
39
tests/asio_test.cc
Normal file
39
tests/asio_test.cc
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include <sled/sled.h>
|
||||||
|
|
||||||
|
TEST_SUITE("asio") {
|
||||||
|
TEST_CASE("io_context") {
|
||||||
|
asio::io_context ctx;
|
||||||
|
int x = 0;
|
||||||
|
asio::dispatch(ctx, [&]{
|
||||||
|
CHECK_EQ(x, 0);
|
||||||
|
++x;
|
||||||
|
});
|
||||||
|
asio::post(ctx, [&]{
|
||||||
|
CHECK_EQ(x, 1);
|
||||||
|
++x;
|
||||||
|
asio::dispatch(ctx, [&]{
|
||||||
|
CHECK_EQ(x, 2);
|
||||||
|
++x;
|
||||||
|
});
|
||||||
|
CHECK_EQ(x, 3);
|
||||||
|
++x;
|
||||||
|
});
|
||||||
|
|
||||||
|
asio::steady_timer timer(ctx, std::chrono::milliseconds(500));
|
||||||
|
timer.async_wait([&](const asio::error_code& ec){
|
||||||
|
if (ec.value() == asio::error::operation_aborted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CHECK_EQ(x, 4);
|
||||||
|
++x;
|
||||||
|
});
|
||||||
|
|
||||||
|
// start ctx
|
||||||
|
{
|
||||||
|
CHECK_EQ(x, 0);
|
||||||
|
ctx.run();
|
||||||
|
CHECK_EQ(x, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user