mirror of
https://github.com/Naios/continuable.git
synced 2026-02-14 22:29:48 +08:00
some thoughts about callbacks
This commit is contained in:
parent
451fb4cc7e
commit
1ac3ebee51
31
test.cpp
31
test.cpp
@ -1,16 +1,37 @@
|
|||||||
|
|
||||||
#include "fluent++.hpp"
|
#include "fluent++.hpp"
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
using Callback = std::function<void(Args...)>;
|
||||||
|
|
||||||
|
void CastSpell(int id, Callback<bool> const& callback)
|
||||||
|
{
|
||||||
|
std::cout << "Cast " << id << std::endl;
|
||||||
|
|
||||||
|
// on success call true
|
||||||
|
callback(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MoveTo(int point, Callback<bool> const& callback)
|
||||||
|
{
|
||||||
|
std::cout << "Move to point " << point << std::endl;
|
||||||
|
|
||||||
|
// on success call true
|
||||||
|
callback(true);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
make_waterfall()
|
make_waterfall<Callback<bool>>()
|
||||||
.then([]
|
.then(std::bind(&CastSpell, 71382, std::placeholders::_1))
|
||||||
|
.then([](bool success, Callback<bool> const& callback)
|
||||||
{
|
{
|
||||||
|
MoveTo(1, callback);
|
||||||
})
|
})
|
||||||
.then([]
|
.then([](bool success)
|
||||||
{
|
{
|
||||||
|
// Do something final
|
||||||
|
std::cout << "finish everything" << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user