mirror of
https://github.com/Naios/continuable.git
synced 2025-12-11 22:19:54 +08:00
more thoughts
This commit is contained in:
parent
775f9bb99a
commit
53dc3a0727
54
mockup.cpp
54
mockup.cpp
@ -1,4 +1,21 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Naios <naios-dev@live.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
@ -39,18 +56,36 @@ Continuable<> operator|| (Continuable<LeftArgs...>&&, Continuable<RightArgs...>&
|
||||
return Continuable<>();
|
||||
}
|
||||
|
||||
Continuable<> http_request(std::string const& /*URL*/)
|
||||
Continuable<> http_request(std::string const& url)
|
||||
{
|
||||
return make_continuable([=](std::function<void(std::string)>&& callback)
|
||||
{
|
||||
// Do request...
|
||||
callback("some HTTP content");
|
||||
});
|
||||
}
|
||||
|
||||
struct ResultSet { };
|
||||
|
||||
Continuable<> mysql_query(std::string const& query)
|
||||
{
|
||||
return make_continuable([=](std::function<void(std::string)>&& callback)
|
||||
{
|
||||
// Do request...
|
||||
|
||||
callback("some HTTP content");
|
||||
callback("a mysql query result");
|
||||
});
|
||||
}
|
||||
|
||||
void test_mockup()
|
||||
{
|
||||
{
|
||||
Continuable<> continuable = make_continuable([]
|
||||
{
|
||||
return "hey";
|
||||
});
|
||||
}
|
||||
|
||||
Continuable<> c1 = make_continuable([]
|
||||
{
|
||||
});
|
||||
@ -63,5 +98,18 @@ void test_mockup()
|
||||
{
|
||||
});
|
||||
|
||||
Continuable<> c11 = (std::move(c1) && std::move(c2)) || std::move(c3);
|
||||
Continuable<> c4 = make_continuable([]
|
||||
{
|
||||
});
|
||||
|
||||
(std::move(c1) && std::move(c2))
|
||||
.then(http_request("https://github.com/") &&
|
||||
http_request("https://www.google.de/") &&
|
||||
mysql_query("SELECT name, session FROM users WHERE id = 3726284"))
|
||||
.then([](std::string github, std::string google, ResultSet user)
|
||||
{
|
||||
// result bla bla
|
||||
});
|
||||
|
||||
// Continuable<> c11 = || std::move(c3);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user