mirror of
https://github.com/Naios/continuable.git
synced 2026-02-09 03:06:41 +08:00
more brainstorming
This commit is contained in:
parent
62f43ea93d
commit
388cda592f
55
test.cpp
55
test.cpp
@ -34,6 +34,23 @@ Continuable<> Log(std::string const& message)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ResultSet
|
||||||
|
{
|
||||||
|
ResultSet(std::size_t affected_) :
|
||||||
|
affected(affected_) { };
|
||||||
|
|
||||||
|
std::size_t affected;
|
||||||
|
};
|
||||||
|
|
||||||
|
Continuable<ResultSet> AsyncQuery(std::string const& query)
|
||||||
|
{
|
||||||
|
return make_continuable([=](Callback<ResultSet>&& callback)
|
||||||
|
{
|
||||||
|
callback(ResultSet(2));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Original method taking an optional callback.
|
// Original method taking an optional callback.
|
||||||
void CastSpell(int id, Optional<Callback<SpellCastResult>> const& callback = boost::none)
|
void CastSpell(int id, Optional<Callback<SpellCastResult>> const& callback = boost::none)
|
||||||
{
|
{
|
||||||
@ -135,7 +152,6 @@ inline auto apply(F && f, T && t)
|
|||||||
|
|
||||||
int main(int /*argc*/, char** /*argv*/)
|
int main(int /*argc*/, char** /*argv*/)
|
||||||
{
|
{
|
||||||
|
|
||||||
CastSpellPromise(1)
|
CastSpellPromise(1)
|
||||||
.then([](SpellCastResult)
|
.then([](SpellCastResult)
|
||||||
{
|
{
|
||||||
@ -146,10 +162,20 @@ int main(int /*argc*/, char** /*argv*/)
|
|||||||
std::cout << "Pause a callback (void test) " << std::endl;
|
std::cout << "Pause a callback (void test) " << std::endl;
|
||||||
})
|
})
|
||||||
.then(Validate())
|
.then(Validate())
|
||||||
|
.then(AsyncQuery("SELECT * FROM `users`")
|
||||||
|
.then([](ResultSet result)
|
||||||
|
{
|
||||||
|
// Evaluate result
|
||||||
|
std::size_t const affected = result.affected;
|
||||||
|
return Log(std::to_string(affected) + " rows affected\n");
|
||||||
|
})
|
||||||
|
)
|
||||||
.then(TrivialPromise("huhu"))
|
.then(TrivialPromise("huhu"))
|
||||||
.then(CastSpellPromise(3))
|
.then(CastSpellPromise(3))
|
||||||
.then(CastSpellPromise(4))
|
.then(CastSpellPromise(4)
|
||||||
.then(CastSpellPromise(5))
|
.then(CastSpellPromise(5))
|
||||||
|
)
|
||||||
|
.then(CastSpellPromise(6))
|
||||||
.then([](SpellCastResult)
|
.then([](SpellCastResult)
|
||||||
{
|
{
|
||||||
return Validate();
|
return Validate();
|
||||||
@ -380,27 +406,22 @@ int main(int /*argc*/, char** /*argv*/)
|
|||||||
|
|
||||||
auto promise = make_continuable()
|
auto promise = make_continuable()
|
||||||
.all(
|
.all(
|
||||||
[]
|
[] {
|
||||||
{
|
return CastSpellPromise(10)
|
||||||
|
.then(CastSpellPromise(15));
|
||||||
// void
|
},
|
||||||
return CastSpellPromise(10);
|
[] {
|
||||||
},
|
return CastSpellPromise(20);
|
||||||
[]
|
})
|
||||||
{
|
|
||||||
|
|
||||||
return CastSpellPromise(20);
|
|
||||||
})
|
|
||||||
.then([](SpellCastResult, SpellCastResult)
|
.then([](SpellCastResult, SpellCastResult)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.then([]
|
.then([]
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
});
|
})
|
||||||
|
.then(TrivialPromise());
|
||||||
|
|
||||||
std::cout << "ok" << std::endl;
|
std::cout << "ok" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user