Skip to content

Instantly share code, notes, and snippets.

@hbarcelos
Last active January 7, 2016 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hbarcelos/1b8820b0320bdf79f727 to your computer and use it in GitHub Desktop.
Save hbarcelos/1b8820b0320bdf79f727 to your computer and use it in GitHub Desktop.
C++ Promises
#include <iostream>
#include <cstdlib>
#include <functional>
template <typename ValueT, typename ReasonT>
class Promise {
private:
enum State {
FULFILLED, REJECTED, PENDING
};
State mState;
ValueT value;
ReasonT reason;
void setState(State s);
public:
Promise(std::function<void(std::function<Promise<ValueT, ReasonT>> resolve,std::function<Promise<ValueT, ReasonT>> reject)>);
~Promise();
};
template <typename ValueT, typename ReasonT>
Promise::Promise(std::function<void(std::function<Promise<ValueT, ReasonT>> resolve,std::function<Promise<ValueT, ReasonT>> reject)>):
mState(Promise::State::PENDING) {
}
template <typename ValueT, typename ReasonT>
Promise::setState(Promise::State s) {
mState = s;
}
int main(int argc, char* argv[]) {
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment