BlackMATov/promise.hpp

promise lifetime ?

wenzhang-dev opened this issue · 1 comments

promise p;
p.then([](int a) {
return 1;
}.then(int b) {
return 2;
});

p.resolve(3);

|then| member function actully calls |attach|, and push lambda/callback into std::vector<>.
the quesion is when p invokes the first |then|, and own this callback and states, however, the second |then| will new a promise, and nobody owns this callback.

so when i try to call p.resolve(3), which only trigger the first calback execution ?

image

maybe i found it. the anwear is that the front promise's callback owns the next promise state.
in this design, once the head promise's callback is clear, all promise chains will be cancelled.