more mockups

This commit is contained in:
Denis Blank 2015-08-09 12:47:20 +02:00 committed by Naios
parent 7bc138738c
commit babdee7325

View File

@ -19,6 +19,7 @@
#include <string> #include <string>
#include <functional> #include <functional>
#include <tuple> #include <tuple>
#include <memory>
template <typename...> template <typename...>
struct Continuable; struct Continuable;
@ -35,10 +36,9 @@ struct Continuable
return Continuable(); return Continuable();
} }
template <typename... Args> Continuable& wrap(std::shared_ptr<std::function<void(std::function<void()>&&)>> dispatcher)
Continuable all(Args&&...)
{ {
return Continuable(); return *this;
} }
}; };
@ -136,9 +136,17 @@ void chain_continuable_mockup()
/// This mockup shows the basic usage and features of continuables waiting for 2 http requests and a database query. /// This mockup shows the basic usage and features of continuables waiting for 2 http requests and a database query.
void final_mockup() void final_mockup()
{ {
// Optional - Create a dispatcher where which dispatches the main chain.
auto const my_dispatcher = std::make_shared<std::function<void(std::function<void()>&&)>>([](std::function<void()>&& function)
{
// Dispatch in same thread or pass to another one
function();
});
Continuable<> c1, c2, c3, c4; Continuable<> c1, c2, c3, c4;
(std::move(c1) && std::move(c2)) (std::move(c1) && std::move(c2))
.wrap(my_dispatcher)
.then(http_request("https://github.com/") && .then(http_request("https://github.com/") &&
http_request("https://www.google.de/") && http_request("https://www.google.de/") &&
mysql_query("SELECT name, session FROM users WHERE id = 3726284")) mysql_query("SELECT name, session FROM users WHERE id = 3726284"))