mirror of
https://github.com/Naios/continuable.git
synced 2026-02-07 10:19:46 +08:00
some minor improvements
This commit is contained in:
parent
c82a721b37
commit
4e9d87fd90
@ -27,7 +27,10 @@ namespace detail
|
|||||||
} // detail
|
} // detail
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
struct ContinuableState
|
struct ContinuableState;
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
struct ContinuableState<Args...>
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -41,12 +44,11 @@ public:
|
|||||||
typedef std::function<void(Callback<_ATy...>&&)> ForwardFunction;
|
typedef std::function<void(Callback<_ATy...>&&)> ForwardFunction;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Functional which expects a callback that is inserted from the Continuable
|
||||||
// Function which expects a callback that is inserted from the Continuable
|
|
||||||
// to chain everything together
|
// to chain everything together
|
||||||
ForwardFunction _callback_insert;
|
ForwardFunction _callback_insert;
|
||||||
|
|
||||||
bool released;
|
bool _released;
|
||||||
|
|
||||||
void Dispatch()
|
void Dispatch()
|
||||||
{
|
{
|
||||||
@ -55,26 +57,27 @@ private:
|
|||||||
public:
|
public:
|
||||||
/// Deleted copy construct
|
/// Deleted copy construct
|
||||||
template <typename _RCTy, typename _RState>
|
template <typename _RCTy, typename _RState>
|
||||||
Continuable(Continuable<_RCTy, _RState> const&) = delete;
|
explicit Continuable(Continuable<_RCTy, _RState> const&) = delete;
|
||||||
|
|
||||||
/// Move construct
|
/// Move construct
|
||||||
template <typename _RCTy, typename _RState>
|
template <typename _RCTy, typename _RState>
|
||||||
Continuable(Continuable<_RCTy, _RState>&& right) : released(right.released)
|
explicit Continuable(Continuable<_RCTy, _RState>&& right)
|
||||||
|
: _released(right._released)
|
||||||
{
|
{
|
||||||
right.released = true;
|
right._released = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct through a ForwardFunction
|
// Construct through a ForwardFunction
|
||||||
template<typename _FTy>
|
template<typename _FTy>
|
||||||
Continuable(_FTy&& callback_insert)
|
Continuable(_FTy&& callback_insert)
|
||||||
: _callback_insert(std::forward<_FTy>(callback_insert)), released(false) { }
|
: _callback_insert(std::forward<_FTy>(callback_insert)), _released(false) { }
|
||||||
|
|
||||||
/// Destructor which calls the dispatch chain if needed.
|
/// Destructor which calls the dispatch chain if needed.
|
||||||
~Continuable()
|
~Continuable()
|
||||||
{
|
{
|
||||||
if (!released)
|
if (!_released)
|
||||||
{
|
{
|
||||||
released = true;
|
_released = true;
|
||||||
Dispatch();
|
Dispatch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,8 +90,8 @@ public:
|
|||||||
template <typename _RCTy, typename _RState>
|
template <typename _RCTy, typename _RState>
|
||||||
Continuable& operator= (Continuable<_RCTy, _RState>&& right)
|
Continuable& operator= (Continuable<_RCTy, _RState>&& right)
|
||||||
{
|
{
|
||||||
released = right.released;
|
_released = right._released;
|
||||||
right.released = true;
|
right._released = true;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,61 +9,6 @@
|
|||||||
#include "functional_unwrap.hpp"
|
#include "functional_unwrap.hpp"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
class fluent_step
|
|
||||||
{
|
|
||||||
bool released;
|
|
||||||
|
|
||||||
void release()
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
std::cout << "-> release" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
fluent_step() : released(false)
|
|
||||||
{
|
|
||||||
std::cout << "+ construct" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
~fluent_step()
|
|
||||||
{
|
|
||||||
std::cout << "- destruct" << std::endl;
|
|
||||||
|
|
||||||
if (!released)
|
|
||||||
release();
|
|
||||||
}
|
|
||||||
|
|
||||||
fluent_step(fluent_step const&) = delete;
|
|
||||||
fluent_step(fluent_step&& right) : released(false)
|
|
||||||
{
|
|
||||||
std::cout << "<-> move" << std::endl;
|
|
||||||
|
|
||||||
right.released = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
fluent_step& operator= (fluent_step const&) = delete;
|
|
||||||
fluent_step& operator= (fluent_step&& right)
|
|
||||||
{
|
|
||||||
released = false;
|
|
||||||
right.released = true;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Callback>
|
|
||||||
fluent_step then(Callback&& callback)
|
|
||||||
{
|
|
||||||
return std::move(*this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename _ATy = void()>
|
|
||||||
fluent_step make_waterfall()
|
|
||||||
{
|
|
||||||
return fluent_step();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct ProtoContinueable
|
struct ProtoContinueable
|
||||||
{
|
{
|
||||||
template <typename Callback>
|
template <typename Callback>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user