Alex Rivera | Logout

Deferred/Promise pattern in C++

Asked 2012-07-09T05:06:21.450
15

I've recently discovered, and fallen in love with, the Deferred/Promise pattern used in jQuery. It just encapsulates so many async use cases, including the wonderful chaining, filtering ability, that I can't believe I missed it for so long.

I've just finished refactoring my AS3 code to use the excellent CodeCatalyst/promise-as3 library (https://github.com/CodeCatalyst/promise-as3), and so started thinking about going back to my C++ code and seeing how I could implement the pattern there.

Before I started coding this myself, I checked to see if it had been done before, and discovered the std::future/std::promise (and boost equivalents), but they are very heavy (they seem use real threads etc, and have a heavy template syntax).

So, my question is: Is there are lightweight, pure C++ implementation of the Deferred/Promise pattern, jQuery-style?

refs:

Edit
Report

1 Answer

8

I am not sure how lightweight a solution you are after, but std::async simplifies the setting up of future/promise pairs a great deal and allows the caller to decide whether a the work is carried out asynchronously by another thread, or with delayed execution in the same thread. In any case, the caller doesn't have to do any explicit thread management.

answered 2012-07-09T05:21:52.237

Your Answer