mirror of
https://github.com/Naios/continuable.git
synced 2026-02-07 10:19:46 +08:00
more work
This commit is contained in:
parent
fe5a922fc7
commit
ff16dfc624
@ -26,25 +26,33 @@ namespace detail
|
|||||||
|
|
||||||
} // detail
|
} // detail
|
||||||
|
|
||||||
template <typename... _ATy>
|
template <typename... Args>
|
||||||
struct Continuable
|
struct ContinuableState
|
||||||
{
|
{
|
||||||
typedef Callback<Callback<_ATy...>&&> ForwardFunction;
|
};
|
||||||
|
|
||||||
|
template <typename _CTy, typename _State = ContinuableState<>>
|
||||||
|
struct Continuable;
|
||||||
|
|
||||||
|
template <typename... _ATy, typename _State>
|
||||||
|
struct Continuable<std::function<void(_ATy...)>, _State>
|
||||||
|
{
|
||||||
|
typedef std::function<void(Callback<_ATy...>&&)> ForwardFunction;
|
||||||
|
|
||||||
// Function 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;
|
||||||
|
|
||||||
Continuable<_ATy...>() { }
|
Continuable() { }
|
||||||
|
|
||||||
template<typename _FTy>
|
template<typename _FTy>
|
||||||
Continuable<_ATy...>(_FTy&& callback_insert)
|
Continuable(_FTy&& callback_insert)
|
||||||
: _callback_insert(std::forward<_FTy>(callback_insert)) { }
|
: _callback_insert(std::forward<_FTy>(callback_insert)) { }
|
||||||
|
|
||||||
template <typename _CTy>
|
template <typename _CTy>
|
||||||
Continuable<_ATy...> then(_CTy&&)
|
Continuable<Callback<_ATy...>> then(_CTy&&)
|
||||||
{
|
{
|
||||||
return Continuable<_ATy...>();
|
return Continuable<Callback<_ATy...>>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -57,10 +65,10 @@ namespace detail
|
|||||||
struct ContinuableFactory<_FTy, _RTy, ::fu::identity<std::function<void(_ATy...)>&&>>
|
struct ContinuableFactory<_FTy, _RTy, ::fu::identity<std::function<void(_ATy...)>&&>>
|
||||||
{
|
{
|
||||||
static auto CreateFrom(_FTy&& functional)
|
static auto CreateFrom(_FTy&& functional)
|
||||||
-> Continuable<_ATy...>
|
-> Continuable<Callback<_ATy...>>
|
||||||
{
|
{
|
||||||
return Continuable<_ATy...>(
|
return Continuable<Callback<_ATy...>>(
|
||||||
typename Continuable<_ATy...>::ForwardFunction(std::forward<_FTy>(functional)));
|
typename Continuable<Callback<_ATy...>>::ForwardFunction(std::forward<_FTy>(functional)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
2
test.cpp
2
test.cpp
@ -19,7 +19,7 @@ enum SpellCastResult
|
|||||||
SPELL_FAILED_ALREADY_BEING_TAMED = 5
|
SPELL_FAILED_ALREADY_BEING_TAMED = 5
|
||||||
};
|
};
|
||||||
|
|
||||||
Continuable<SpellCastResult> CastSpell(int id)
|
Continuable<Callback<SpellCastResult>> CastSpell(int id)
|
||||||
{
|
{
|
||||||
return make_continuable([=](Callback<SpellCastResult>&& callback)
|
return make_continuable([=](Callback<SpellCastResult>&& callback)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user