mirror of
https://github.com/Naios/continuable.git
synced 2025-12-07 01:06:44 +08:00
more mockups
This commit is contained in:
parent
7bc138738c
commit
babdee7325
14
mockup.cpp
14
mockup.cpp
@ -19,6 +19,7 @@
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <tuple>
|
||||
#include <memory>
|
||||
|
||||
template <typename...>
|
||||
struct Continuable;
|
||||
@ -35,10 +36,9 @@ struct Continuable
|
||||
return Continuable();
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
Continuable all(Args&&...)
|
||||
Continuable& wrap(std::shared_ptr<std::function<void(std::function<void()>&&)>> dispatcher)
|
||||
{
|
||||
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.
|
||||
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;
|
||||
|
||||
(std::move(c1) && std::move(c2))
|
||||
.wrap(my_dispatcher)
|
||||
.then(http_request("https://github.com/") &&
|
||||
http_request("https://www.google.de/") &&
|
||||
mysql_query("SELECT name, session FROM users WHERE id = 3726284"))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user