I am trying to create the following promise syntaxes:
I want the secondary then to be called after the post function, how can I do that?
randomBytes.then(function() {
return requestPromise.post(....);
}).then(function() {
// I want this part to be called after the POST
});
The fact this already works (as the comment said - assuming .post returns a promise) is pretty much the point of then - it allows you to wait for stuff.
If you return a promise from then, the chain will assume its state and thus will only call the following segments after it has completed.
randomBytes.then(function() {
return requestPromise.post(....);
}).then(function() {
// WILL ALWAYS BE CALLED AFTER THE POST
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With