minor improvements

This commit is contained in:
Denis Blank 2015-08-09 18:34:13 +02:00 committed by Naios
parent 9f300419d2
commit 89ce1a9616

View File

@ -17,7 +17,7 @@ This library aims to provide full support for **async continuation chains with c
Continuable<std::string> continuable = Continuable<std::string> continuable =
make_continuable([](Callback<std::string>&& callback) make_continuable([](Callback<std::string>&& callback)
{ {
callback("some data"); callback("some data");
}); });
``` ```
@ -27,13 +27,14 @@ Continuable<std::string> continuable =
```c++ ```c++
Continuable<ResultSet> mysql_query(std::string&& query) Continuable<ResultSet> mysql_query(std::string&& query)
{ {
return make_continuable([query = std::move(query)](Callback<ResultSet>&& callback) mutable return make_continuable(
{ [query = std::move(query)](Callback<ResultSet>&& callback) mutable
// Pass the callback to the handler {
// which calls the callback when finished. // Pass the callback to the handler
// Everything which takes a callback works with continuables. // which calls the callback when finished.
mysql_handle_async_query(std::move(query), std::move(callback)); // Everything which takes a callback works with continuables.
}); mysql_handle_async_query(std::move(query), std::move(callback));
});
} }
// You can use the helper function like you would normally do: // You can use the helper function like you would normally do:
@ -41,7 +42,7 @@ mysql_query("DELETE FROM users WHERE id = 27361");
// Or using chaining to handle the result which is covered in the next topic . // Or using chaining to handle the result which is covered in the next topic .
mysql_query("SELECT id, name FROM users") mysql_query("SELECT id, name FROM users")
.then([](ResultSet result) .then([](ResultSet result)
{ {
}); });
``` ```
@ -52,11 +53,11 @@ Chaining continuables is very easy:
```c++ ```c++
(mysql_query("SELECT id, name FROM users") (mysql_query("SELECT id, name FROM users")
&& http_request("http://github.com")) && http_request("http://github.com"))
.then([](ResultSet result, std::string page_content) .then([](ResultSet result, std::string page_content)
{ {
// Pass one argument to the next continuation... // Pass one argument to the next continuation...
return page_content.empty(); return page_content.empty();
// ... or pass multiple args using tuples... // ... or pass multiple args using tuples...
return std::make_tuple(std::move(result), page_content.empty()); return std::make_tuple(std::move(result), page_content.empty());