Skip to content

Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Q

A simple implementation of Q in C++. If you love promises, you'll love this.

Usage:

#include"Q.h"
Promise *my_promise_method() {
Deferred *deferred = Q::defer();
// do something...if (/* we want to resolve the promise */) {
deferred->resolve(PromiseVal::value((void*)true));
} else {
// we want to reject the promise
deferred->reject((void*)"Something bad happened");
}
// return the promisereturn deferred->promise();
}
// call thenmy_promise_method()->then([](PromiseVal *value) -> PromiseVal * {
// success// extract your data from the valuebool my_bool = value->getData<bool>();
//...returnPromiseVal::null(); // return a PromiseVal (for chainability)
}, [](void *error) {
// error
}, []() {
// finally
});

Promise.then returns a promise, so you can chain then methods. You can also return a promise value with PromiseVal::promise, and Q will wait for that promise to be resolved before continuing down the chain.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages