feat update
This commit is contained in:
36
src/async/async.cc
Normal file
36
src/async/async.cc
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "sled/async/async.h"
|
||||
#include "sled/synchronization/event.h"
|
||||
#include "sled/system/thread_pool.h"
|
||||
#include "sled/utility/move_on_copy.h"
|
||||
// clang-format off
|
||||
#include <async++.h>
|
||||
|
||||
// clang-format on
|
||||
namespace async {
|
||||
sled::FiberScheduler &
|
||||
default_scheduler()
|
||||
{
|
||||
static sled::FiberScheduler scheduler;
|
||||
return scheduler;
|
||||
}
|
||||
}// namespace async
|
||||
|
||||
namespace sled {
|
||||
|
||||
void
|
||||
SleepWaitHandler(async::task_wait_handle t)
|
||||
{
|
||||
sled::Event event;
|
||||
t.on_finish([&] { event.Set(); });
|
||||
event.Wait(sled::Event::kForever);
|
||||
}
|
||||
|
||||
void
|
||||
FiberScheduler::schedule(async::task_run_handle t)
|
||||
{
|
||||
static ThreadPool thread_pool;
|
||||
auto move_on_copy = sled::MakeMoveOnCopy(t);
|
||||
thread_pool.PostTask([move_on_copy] { move_on_copy.value.run_with_wait_handler(SleepWaitHandler); });
|
||||
}
|
||||
|
||||
}// namespace sled
|
||||
10
src/async/async_test.cc
Normal file
10
src/async/async_test.cc
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <sled/async/async.h>
|
||||
|
||||
TEST(Async, task)
|
||||
{
|
||||
auto task1 = async::spawn([] { return 42; }).then([](int value) { return value * 3; }).then([](int value) {
|
||||
EXPECT_EQ(value, 126);
|
||||
});
|
||||
task1.wait();
|
||||
}
|
||||
4
src/futures/detail/just_test.cc
Normal file
4
src/futures/detail/just_test.cc
Normal file
@@ -0,0 +1,4 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <sled/futures/detail/just.h>
|
||||
|
||||
TEST(Just, basic) { auto s1 = sled::detail::Just(42); }
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <sled/futures/promise.h>
|
||||
|
||||
TEST(Promise, Basic)
|
||||
{
|
||||
@@ -21,7 +22,7 @@ TEST(Promise, Basic)
|
||||
|
||||
TEST(Future, Basic)
|
||||
{
|
||||
auto p = sled::Promise<int>();
|
||||
auto p = sled::Promise<int>();
|
||||
auto future = p.GetFuture()
|
||||
.Then([](int v) {
|
||||
EXPECT_EQ(v, 1);
|
||||
|
||||
Reference in New Issue
Block a user