I am writing a library in C++ (making use of many C++11 features) that (as far as I can tell) implements the promise pattern.

The library consists of a class that makes asynchronous network requests. When a user of this class invokes a method that issues a network request, an instance of another class (we'll call it the "promise class") is returned that provides methods for canceling the request.

Since this application uses the Qt framework, the promise class also emits signals when certain events happen, one of which is the successful completion of the request. Because the result of the network request is often included when the signal is emitted, I feel that this class implements the promise pattern.

According to the Wikipedia article:

"In computer science, future, promise, and delay refer to constructs used for synchronizing in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially unknown, usually because the computation of its value is yet incomplete."

* emphasis mine

Have I missed anything? Does my class indeed implement the promise pattern?

  • 3
    You mean, like std::promise<T>?
    – DeadMG
    Feb 12, 2013 at 20:00
  • Probably as in Futures and Promises as the wikipedia article he linked. Feb 12, 2013 at 20:03
  • @DeadMG: Well sort of... except this isn't a multithreaded application. Feb 12, 2013 at 20:11

1 Answer 1


I think you have implemented it. Design patterns necessarily have somewhat generous definitions, as they need to work in a variety of application contexts.

Note: If your particular context is a homework problem and you are gathering evidence to challenge an unfavorable grade, well, that's between your and your professor. :) Out in industry, clean, functional code carries a lot more weight than compliance with narrow pattern definitions.

  • Nope, not a homework problem. Actually, I wanted to use the word "promise" in the class name and wanted to make sure it was accurately labelled. Feb 13, 2013 at 2:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.