Some doc fixes

This commit is contained in:
Denis Blank 2020-04-04 23:27:32 +02:00
parent adc75655f4
commit 5fbc9c4a59
4 changed files with 56 additions and 22 deletions

View File

@ -1,5 +1,5 @@
/* /*
Copyright(c) 2015 - 2019 Denis Blank <denis.blank at outlook dot com> Copyright(c) 2015 - 2020 Denis Blank <denis.blank at outlook dot com>
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal of this software and associated documentation files(the "Software"), to deal
@ -76,7 +76,7 @@ your personal experience in using the library to improve it.
Continuable is licensed under the MIT license: Continuable is licensed under the MIT license:
> >
> Copyright(c) 2015 - 2019 Denis Blank <denis.blank at outlook dot com> > Copyright(c) 2015 - 2020 Denis Blank <denis.blank at outlook dot com>
> >
> Permission is hereby granted, free of charge, to any person obtaining a copy > Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files(the "Software"), to deal > of this software and associated documentation files(the "Software"), to deal

View File

@ -70,5 +70,30 @@ async_resolve("127.0.0.1", "daytime")
}); });
\endcode \endcode
\section tutorial-promisify-continuables-boost-ct asio and boost::asio async completion tokens
Since version 4.0.0 continuable also supports asio async initiation tokens.
- Boost 1.70 and asio 1.13.0 is required for the async initiation
- Until boost 1.72 and asio 1.16.0 overhead through an additional type
erasure is added. It is recommeded to update to those versions.
The special static variable \ref cti::use_continuable can be appended to any
(boost) asio function that accepts a callback to make it return a \ref continuable_base.
\code{.cpp}
#include <continuable/continuable.hpp>
#include <continuable/external/asio.hpp>
#include <asio.hpp>
// ...
asio::tcp::resolver resolver(...);
resolver.async_resolve("127.0.0.1", "daytime", cti::use_continuable)
.then([](asio::udp::resolver::iterator iterator) {
// ...
});
\endcode
*/ */
} }

View File

@ -30,28 +30,37 @@ namespace cti {
Sometimes it's required to change a \ref continuable_base object by its whole. Sometimes it's required to change a \ref continuable_base object by its whole.
Thus the library offers the ability to apply a transformation to any Thus the library offers the ability to apply a transformation to any
\ref continuable_base through using \link continuable_base::apply apply \endlink \ref continuable_base through using \link continuable_base::apply apply \endlink.
or \link continuable_base::operator | its operator | \endlink.
A transformation accepts a \ref continuable_base and returns A transformation is a callable object that accepts a \ref continuable_base
an arbitrary object. and returns an arbitrary object
To create a transformation use the \ref make_transform function:
\code{.cpp}
auto transform = cti::make_transform([] (auto&& continuable) {
// Change the continuable
return std::forward<decltype(continuable)>(continuable);
});
\endcode
The library provides several transforms already as part of the The library provides several transforms already as part of the
\ref cti::transforms namespace. \ref cti::transforms namespace.
\section tutorial-transforming-continuables-wait Synchronous wait
The library is capable of converting every asynchronous control flow
into a synchronous one through \ref transforms::wait, \ref transforms::wait_for
and \ref transforms::wait_until.
\code{.cpp}
std::string response = http_request("github.com")
.apply(cti::transforms::wait());
std::string response = http_request("github.com")
.apply(cti::transforms::wait_for(std::chrono::seconds(5)));
std::string response = http_request("github.com")
.apply(cti::transforms::wait_until(...));
\endcode
The current thread will be blocked until the result has arrived
\section tutorial-transforming-continuables-future Conversion into std::future \section tutorial-transforming-continuables-future Conversion into std::future
The library is capable of converting (*futurizing*) every continuable into a The library is capable of converting (*futurizing*) every continuable into a
fitting `std::future` through the \ref transforms::futurize transform: fitting `std::future` through the \ref transforms::to_future transform:
\code{.cpp} \code{.cpp}
std::future<std::string> future = http_request("github.com") std::future<std::string> future = http_request("github.com")
@ -59,17 +68,17 @@ std::future<std::string> future = http_request("github.com")
// Do sth... // Do sth...
return http_request("travis-ci.org") || http_request("atom.io"); return http_request("travis-ci.org") || http_request("atom.io");
}) })
.apply(cti::transforms::futurize()); .apply(cti::transforms::to_future());
// ^^^^^^^^ // ^^^^^^^^
\endcode \endcode
Multiple arguments which can't be handled by `std::future` itself are Multiple arguments which can't be handled by `std::future` itself are
converted into `std::tuple`, see \ref transforms::futurize for details. converted into `std::tuple`, see \ref transforms::to_future for details.
\code{.cpp} \code{.cpp}
std::future<std::tuple<std::string, std::string>> future = std::future<std::tuple<std::string, std::string>> future =
(http_request("travis-ci.org") && http_request("atom.io")) (http_request("travis-ci.org") && http_request("atom.io"))
.apply(cti::transforms::futurize()); .apply(cti::transforms::to_future());
\endcode \endcode
*/ */
} }

View File

@ -623,7 +623,7 @@ public:
/// Invalidates the continuable and returns its immediate invocation result. /// Invalidates the continuable and returns its immediate invocation result.
/// ///
/// This method can be used to specialize the asynchronous control flow /// This method can be used to specialize the asynchronous control flow
/// based on whether the continuable ìs_ready at every time, /// based on whether the continuable_base is_ready at every time,
/// which is true for a continuable created through the following functions: /// which is true for a continuable created through the following functions:
/// - make_ready_continuable /// - make_ready_continuable
/// - make_exceptional_continuable /// - make_exceptional_continuable