mirror of
https://github.com/Naios/continuable.git
synced 2025-12-07 01:06:44 +08:00
some work
This commit is contained in:
parent
8b5a90aa5f
commit
ad7f1511a2
@ -27,14 +27,16 @@ struct Continuable;
|
|||||||
template <typename... _ATy>
|
template <typename... _ATy>
|
||||||
struct Continuable<Callback<_ATy...>>
|
struct Continuable<Callback<_ATy...>>
|
||||||
{
|
{
|
||||||
|
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
|
||||||
std::function<void(Callback<_ATy...>)> _callback_insert;
|
ForwardFunction _callback_insert;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Continuable<Callback<_ATy...>>() { }
|
Continuable<Callback<_ATy...>>() { }
|
||||||
Continuable<Callback<_ATy...>>(std::function<void(Callback<_ATy...>)>&& callback_insert)
|
Continuable<Callback<_ATy...>>(ForwardFunction&& callback_insert)
|
||||||
: _callback_insert(std::forward<std::function<void(Callback<_ATy...>)>>(callback_insert)) { }
|
: _callback_insert(std::forward<ForwardFunction>(callback_insert)) { }
|
||||||
|
|
||||||
template <typename _CTy>
|
template <typename _CTy>
|
||||||
Continuable<Callback<_ATy...>>& then(_CTy&& callback)
|
Continuable<Callback<_ATy...>>& then(_CTy&& callback)
|
||||||
@ -49,7 +51,7 @@ namespace detail
|
|||||||
struct ContinuableFactory;
|
struct ContinuableFactory;
|
||||||
|
|
||||||
template <typename _FTy, typename _RTy, typename... _ATy>
|
template <typename _FTy, typename _RTy, typename... _ATy>
|
||||||
struct ContinuableFactory<_FTy, _RTy, ::fu::identity<Callback<_ATy...>>>
|
struct ContinuableFactory<_FTy, _RTy, ::fu::identity<Callback<_ATy...>&&>>
|
||||||
{
|
{
|
||||||
static auto CreateFrom(_FTy&& functional)
|
static auto CreateFrom(_FTy&& functional)
|
||||||
-> Continuable<Callback<_ATy...>>
|
-> Continuable<Callback<_ATy...>>
|
||||||
|
|||||||
36
test.cpp
36
test.cpp
@ -18,6 +18,7 @@ enum SpellCastResult
|
|||||||
SPELL_FAILED_ALREADY_BEING_TAMED = 5
|
SPELL_FAILED_ALREADY_BEING_TAMED = 5
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
ProtoContinueable ProtoCastSpell(int id)
|
ProtoContinueable ProtoCastSpell(int id)
|
||||||
{
|
{
|
||||||
std::cout << "Cast " << id << std::endl;
|
std::cout << "Cast " << id << std::endl;
|
||||||
@ -40,22 +41,7 @@ void ProtoCastSpell(int id, Callback<SpellCastResult> const& callback)
|
|||||||
|
|
||||||
// on success call the callback with SPELL_FAILED_SUCCESS
|
// on success call the callback with SPELL_FAILED_SUCCESS
|
||||||
callback(SPELL_FAILED_SUCCESS);
|
callback(SPELL_FAILED_SUCCESS);
|
||||||
}
|
|
||||||
|
|
||||||
Continuable<Callback<SpellCastResult>>
|
|
||||||
CastSpell(int id)
|
|
||||||
{
|
|
||||||
auto tt = 1;
|
|
||||||
/*make_continuable([=](Callback<SpellCastResult> const& callback)
|
|
||||||
{
|
|
||||||
std::cout << "Cast " << id << std::endl;
|
|
||||||
|
|
||||||
// on success call the callback with SPELL_FAILED_SUCCESS
|
|
||||||
callback(SPELL_FAILED_SUCCESS);
|
|
||||||
});*/
|
|
||||||
|
|
||||||
return Continuable<Callback<SpellCastResult>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProtoMoveTo(int point, Callback<bool> const& callback)
|
void ProtoMoveTo(int point, Callback<bool> const& callback)
|
||||||
{
|
{
|
||||||
@ -65,8 +51,23 @@ void ProtoMoveTo(int point, Callback<bool> const& callback)
|
|||||||
callback(true);
|
callback(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Continuable<Callback<SpellCastResult>> CastSpell(int id)
|
||||||
|
{
|
||||||
|
return make_continuable([=](Callback<SpellCastResult>&& callback)
|
||||||
|
{
|
||||||
|
std::cout << "Cast " << id << std::endl;
|
||||||
|
|
||||||
|
// on success call the callback with SPELL_FAILED_SUCCESS
|
||||||
|
callback(SPELL_FAILED_SUCCESS);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
make_waterfall<Callback<SpellCastResult>>()
|
make_waterfall<Callback<SpellCastResult>>()
|
||||||
// .then(std::bind(&CastSpell, 71382, std::placeholders::_1))
|
// .then(std::bind(&CastSpell, 71382, std::placeholders::_1))
|
||||||
.then([](SpellCastResult result, Callback<bool> const& callback)
|
.then([](SpellCastResult result, Callback<bool> const& callback)
|
||||||
@ -166,11 +167,12 @@ int main(int argc, char** argv)
|
|||||||
std::cout << "huhu" << std::endl;
|
std::cout << "huhu" << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
auto wrapped = make_weak_wrapped_callback(weak_2);
|
auto wrapped = make_weak_wrapped_callback(weak_2);
|
||||||
auto wrapped2 = make_weak_wrapped_callback(WeakCallback<>(weak_2));
|
auto wrapped2 = make_weak_wrapped_callback(WeakCallback<>(weak_2));
|
||||||
wrapped();
|
wrapped();
|
||||||
wrapped2();
|
wrapped2();
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef Continuable<Callback<bool>> cont123;
|
typedef Continuable<Callback<bool>> cont123;
|
||||||
@ -192,7 +194,7 @@ int main(int argc, char** argv)
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Wraps a callback function into a continuable
|
// Wraps a callback function into a continuable
|
||||||
auto cba1 = make_continuable([=](Callback<SpellCastResult> callback)
|
auto cba1 = make_continuable([=](Callback<SpellCastResult>&& callback)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user