mirror of
https://github.com/Naios/continuable.git
synced 2025-12-08 01:36:46 +08:00
some brainstorming...
This commit is contained in:
parent
27359da843
commit
9a135add56
37
test.cpp
37
test.cpp
@ -113,6 +113,43 @@ int main(int /*argc*/, char** /*argv*/)
|
||||
typedef fu::requires_functional_constructible<std::function<void()>>::type test_assert1;
|
||||
// typedef fu::requires_functional_constructible<std::vector<int>>::type test_assert2;
|
||||
|
||||
// Brainstorming: this shows an example callback chain
|
||||
// Given by continuable
|
||||
std::function<void(Callback<SpellCastResult>&&)> fn1 = [](Callback<SpellCastResult>&& callback)
|
||||
{
|
||||
callback(SPELL_FAILED_AFFECTING_COMBAT);
|
||||
};
|
||||
|
||||
// Implemented by user
|
||||
std::function<std::function<void(Callback<bool>&&)>(SpellCastResult)> cn1 = [](SpellCastResult)
|
||||
{
|
||||
// Given by continuable
|
||||
return [](Callback<bool>&& callback)
|
||||
{
|
||||
callback(true);
|
||||
};
|
||||
};
|
||||
|
||||
// Auto created wrapper by the continuable
|
||||
std::function<void(SpellCastResult)> wr1 = [&cn1](SpellCastResult result)
|
||||
{
|
||||
// Wrapper functional to process unary or multiple promised callbacks
|
||||
// Returned from the user
|
||||
std::function<void(Callback<bool>&&)> fn2 = cn1(result);
|
||||
|
||||
fn2([](bool val)
|
||||
{
|
||||
// Finished
|
||||
std::cout << "Callback chain finished! -> " << val << std::endl;
|
||||
});
|
||||
};
|
||||
|
||||
Callback<> entry = [&]
|
||||
{
|
||||
fn1(std::move(wr1));
|
||||
};
|
||||
|
||||
entry();
|
||||
|
||||
std::cout << "ok" << std::endl;
|
||||
return 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user