fix
All checks were successful
linux-x64-gcc / linux-gcc (Release) (push) Successful in 1m50s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 57s

This commit is contained in:
tqcq 2024-03-25 23:29:18 +08:00
parent 53ecd8dd13
commit a10703176c
6 changed files with 82 additions and 2 deletions

View 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

View File

@ -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>

View File

@ -96,6 +96,7 @@ struct RetryOperation {
template<typename S>
struct RetrySender {
using result_t = typename S::result_t;
S sender;
int retry_count;

View File

@ -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;

View File

@ -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

View File

@ -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;