Promise/A+ like javascript in cpp

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Promise/A+ like javascript in cpp

Boost - Dev mailing list
Hi,

Javascript Promise creates a task chain to help develop asynchronized
application with single thread.

I did not find a good implement of this kind of "Promise" in c++, so i
create one named "promise-cpp" here --

   https://github.com/xhawk18/promise-cpp

with which, we can write asynchronized tasks like sequential flows.

Here's an example of promisifed http client in boost::asio --


https://github.com/xhawk18/promise-cpp/blob/master/test/asio_http_client.cpp

"promise-cpp" would be the best friend to  boost::asio's asynchronized task
for single thread, and it is not std::promise.

Thanks for you reviewing this library and any suggestion will be
appreciated!

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Promise/A+ like javascript in cpp

Boost - Dev mailing list
On 26/07/2018 00:15, hawk x wrote:
> Javascript Promise creates a task chain to help develop asynchronized
> application with single thread.
>
> I did not find a good implement of this kind of "Promise" in c++

std::future::then was proposed for C++17, but didn't make it in.  Boost
does support it, however, as does an STL that implements the Concurrency
TS (as std::experimental::future::then).

https://www.boost.org/doc/libs/1_67_0/doc/html/thread/synchronization.html#thread.synchronization.futures.then


Additionally, Boost.Asio supports using coroutines for implementing
asynchronous tasks, which are even better than a then-chain and read
even more like plain synchronous code.

https://www.boost.org/doc/libs/1_67_0/doc/html/boost_asio/overview/core/spawn.html

https://www.boost.org/doc/libs/1_67_0/doc/html/boost_asio/example/cpp11/spawn/echo_server.cpp


Currently coroutines are a pure library feature (supported by
Boost.Context and Boost.Coroutine), but they are expected to be
supported directly by C++20 compilers, and by C++17 compilers that
implement the Coroutine TS (VS 2017 already supports co_await, for example).

https://www.boost.org/doc/libs/1_67_0/doc/html/boost_asio/overview/core/coroutines_ts.html

https://www.boost.org/doc/libs/1_67_0/doc/html/boost_asio/examples/cpp17_examples.html


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Promise/A+ like javascript in cpp

Boost - Dev mailing list
boost::coroutine and std::future are all excellent solutions for
concurrency programming.
But if there's many concurrent tasks, event-loop based multi-task in SINGLE
thread will have the best performance.

while std::future is designed for mulitthread, and std::future::then is not
suitable for event-loop based multi-task in SINGLE thread,
that's why I wrote "promise-cpp".






2018-07-27 8:50 GMT+08:00 Gavin Lambert via Boost <[hidden email]>:

> On 26/07/2018 00:15, hawk x wrote:
>
>> Javascript Promise creates a task chain to help develop asynchronized
>> application with single thread.
>>
>> I did not find a good implement of this kind of "Promise" in c++
>>
>
> std::future::then was proposed for C++17, but didn't make it in.  Boost
> does support it, however, as does an STL that implements the Concurrency TS
> (as std::experimental::future::then).
>
> https://www.boost.org/doc/libs/1_67_0/doc/html/thread/synchr
> onization.html#thread.synchronization.futures.then
>
>
> Additionally, Boost.Asio supports using coroutines for implementing
> asynchronous tasks, which are even better than a then-chain and read even
> more like plain synchronous code.
>
> https://www.boost.org/doc/libs/1_67_0/doc/html/boost_asio/
> overview/core/spawn.html
>
> https://www.boost.org/doc/libs/1_67_0/doc/html/boost_asio/
> example/cpp11/spawn/echo_server.cpp
>
>
> Currently coroutines are a pure library feature (supported by
> Boost.Context and Boost.Coroutine), but they are expected to be supported
> directly by C++20 compilers, and by C++17 compilers that implement the
> Coroutine TS (VS 2017 already supports co_await, for example).
>
> https://www.boost.org/doc/libs/1_67_0/doc/html/boost_asio/
> overview/core/coroutines_ts.html
>
> https://www.boost.org/doc/libs/1_67_0/doc/html/boost_asio/
> examples/cpp17_examples.html
>
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman
> /listinfo.cgi/boost
>

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Promise/A+ like javascript in cpp

Boost - Dev mailing list
On 27/07/2018 14:13, hawk x wrote:
> boost::coroutine and std::future are all excellent solutions for
> concurrency programming.
> But if there's many concurrent tasks, event-loop based multi-task in SINGLE
> thread will have the best performance.

coroutines can be used to manage concurrent tasks on a single thread.

Boost.Asio is one way to manage those tasks with an event loop (simply
have a single thread running the io_service/io_context); additional work
can be posted both from "inside" and outside.

Boost.Fiber
(https://www.boost.org/doc/libs/1_67_0/libs/fiber/doc/html/index.html)
is another way.  This also supports futures, although not currently
then-able ones.


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Promise/A+ like javascript in cpp

Boost - Dev mailing list
On Fri, Jul 27, 2018, 1:58 AM Gavin Lambert via Boost <[hidden email]>
wrote:

Boost.Fiber
> (https://www.boost.org/doc/libs/1_67_0/libs/fiber/doc/html/index.html)
> is another way.  This also supports futures, although not currently
> then-able ones.
>

Boost.Fiber doesn't need fibers::future::then - just suspend the fiber. If
you need more concurrency than that, launch another fiber. then() is
redundant with coroutine and fiber concurrency.

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost