How Do You Call A Function With Parameters In A .then Function In A Javascript Promise String?
I am converting my AWS lambda functions, written in node.js, to use promises instead of callbacks. I'm wrapping all of my functions in the handler with the handler code. I'm tryi
Solution 1:
You can use Promise.all()
, .then()
, Function.prototype.bind()
; return
rp.get()
from getData()
returnPromise.all(users.map(function(user) {
userId = // the value from the user record; // Request a tokenvar tokenParams = {
an object of params
};
returngetToken(tokenParams)
.then(getData.bind(null, userId, user.dbName))
.catch(function(e) {
console.log("caught an error");
throw e
});
}))
Solution 2:
When using a promise, your code should look more like this.
when.try(() => {
return api.some_api_call
})
.then((results) => {
const whatIAmLookingFor = {
data: results.data
};
someFunction(whatIAmLookingFor);
})
.then(() => {
return api.some_other_api_call
})
.then((results) => {
const whatIAmLookingFor = {
data: results.data
};
someOtherFunction(whatIAmLookingFor);
.catch(() => {
console.log('oh no!');
})
});
Post a Comment for "How Do You Call A Function With Parameters In A .then Function In A Javascript Promise String?"