fix
This commit is contained in:
parent
53ecd8dd13
commit
a10703176c
69
include/sled/futures/detail/delay.h
Normal file
69
include/sled/futures/detail/delay.h
Normal file
@ -0,0 +1,69 @@
|
||||
#ifndef SLED_FUTURES_DETAIL_DELAY_H
|
||||
#define SLED_FUTURES_DETAIL_DELAY_H
|
||||
|
||||
#include "sled/units/time_delta.h"
|
||||
#include "traits.h"
|
||||
#include <exception>
|
||||
|
||||
namespace sled {
|
||||
namespace detail {
|
||||
|
||||
template<typename R>
|
||||
struct DelayReceiver {
|
||||
R receiver;
|
||||
sled::TimeDelta delta;
|
||||
bool stopped = false;
|
||||
|
||||
template<typename U>
|
||||
void SetValue(U &&val)
|
||||
{
|
||||
if (stopped) { return; }
|
||||
receiver.SetValue(std::forward<U>(val));
|
||||
}
|
||||
|
||||
void SetError(std::exception_ptr e)
|
||||
{
|
||||
if (stopped) { return; }
|
||||
receiver.SetError(e);
|
||||
}
|
||||
|
||||
void SetStopped()
|
||||
{
|
||||
if (stopped) { return; }
|
||||
stopped = true;
|
||||
receiver.SetStopped();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename S, typename R>
|
||||
struct DelayOperation {
|
||||
ConnectResultT<S, R> op;
|
||||
|
||||
void Start() { op.Start(); }
|
||||
|
||||
void Stop() { op.Stop(); }
|
||||
};
|
||||
|
||||
template<typename S>
|
||||
struct DelaySender {
|
||||
using result_t = typename S::result_t;
|
||||
S sender;
|
||||
sled::TimeDelta delta;
|
||||
|
||||
template<typename R>
|
||||
DelayOperation<S, DelayReceiver<R>> Connect(R receiver)
|
||||
{
|
||||
return {sender.Connect(DelayReceiver<R>{receiver, delta})};
|
||||
}
|
||||
};
|
||||
|
||||
template<typename S>
|
||||
DelaySender<S>
|
||||
Delay(S sender, sled::TimeDelta const &delta)
|
||||
{
|
||||
return {sender, delta};
|
||||
}
|
||||
|
||||
}// namespace detail
|
||||
}// namespace sled
|
||||
#endif// SLED_FUTURES_DETAIL_DELAY_H
|
@ -1,6 +1,7 @@
|
||||
#ifndef SLED_FUTURES_DETAIL_JUST_H
|
||||
#define SLED_FUTURES_DETAIL_JUST_H
|
||||
|
||||
#include "traits.h"
|
||||
#include <memory>
|
||||
|
||||
namespace sled {
|
||||
@ -18,6 +19,7 @@ struct JustOperation {
|
||||
|
||||
template<typename T>
|
||||
struct JustSender {
|
||||
using result_t = T;
|
||||
T value;
|
||||
|
||||
template<typename R>
|
||||
|
@ -96,6 +96,7 @@ struct RetryOperation {
|
||||
|
||||
template<typename S>
|
||||
struct RetrySender {
|
||||
using result_t = typename S::result_t;
|
||||
S sender;
|
||||
int retry_count;
|
||||
|
||||
|
@ -49,6 +49,7 @@ struct ThenOperation {
|
||||
|
||||
template<typename S, typename F>
|
||||
struct ThenSender {
|
||||
using result_t = invoke_result_t<F, typename S::result_t>;
|
||||
S sender;
|
||||
F func;
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef SLED_FUTURES_DETAIL_TRAITS_H
|
||||
#define SLED_FUTURES_DETAIL_TRAITS_H
|
||||
|
||||
#include "sled/exec/detail/invoke_result.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace sled {
|
||||
@ -13,6 +15,9 @@ struct ConnectResult {
|
||||
template<typename S, typename R>
|
||||
using ConnectResultT = typename ConnectResult<S, R>::type;
|
||||
|
||||
template<typename F, typename... Args>
|
||||
using invoke_result_t = eggs::invoke_result_t<F, Args...>;
|
||||
|
||||
}// namespace detail
|
||||
}// namespace sled
|
||||
#endif// SLED_FUTURES_DETAIL_TRAITS_H
|
||||
|
@ -18,8 +18,9 @@ struct ViaReceiver {
|
||||
{
|
||||
if (stopped) { return; }
|
||||
try {
|
||||
auto func = std::bind(&R::SetValue, &receiver, std::forward<U>(val));
|
||||
schedule(std::move(func));
|
||||
// auto func = std::bind(&R::SetValue, &receiver, std::forward<U>(val));
|
||||
// schedule(std::move(func));
|
||||
schedule([this, val]() mutable { receiver.SetValue(std::move(val)); });
|
||||
} catch (...) {
|
||||
SetError(std::current_exception());
|
||||
}
|
||||
@ -50,6 +51,7 @@ struct ViaOperation {
|
||||
|
||||
template<typename S, typename F>
|
||||
struct ViaSender {
|
||||
using result_t = typename S::result_t;
|
||||
S sender;
|
||||
F schedule;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user