This time I created a Promise.all Call like this. tools.isMember and tools.unsubscribe will return promise objects.
tools.isMember(userid)
.then(results => {
Promise.all(
Object.keys(results).map((key, index) => {
tools.unsubscribe(results[index], userid)
})
)
})
.then(unsubscribe => { console.log('Unsubscribed Results => ', unsubscribed)})
.catch(err => console.log(err))
Console prints
Unsubscribed Results => undefined
I try to move the logging up a little to debug and i place the console.log at where tools.unsubscribe is
tools.isMember(userid)
.then(results => {
Promise.all(
Object.keys(results).map((key, index) => {
tools.unsubscribe(results[index], userid).then(result => { console.log('Result from Tools => " result) }) //Added Logging Here
})
)
})
.then(unsubscribe => { console.log('Unsubscribed Results => ', unsubscribe)})
.catch(err => console.log(err))
Now console shows
Unsubscribed Results => undefined
Result from Tools => 1
So now I know the promise is returning the expected results from tools.unsubscribed however the Promise.all is supposed to return an array with all the results? It's now showing undefined.
I've tried many different trouble shooting but i'm new to Promise. Trying to figure out what went wrong with Promise.all this time.
Updated @Bergie : Added return on tools.unsubscribe
tools.isMember(userid)
.then(results => {
Promise.all(
Object.keys(results).map((key, index) => {
tools.unsubscribe(results[index], userid).then(result => { return result })
})
).then(result => { return result }) //Tryning to interpret Bergie's answer
})
.then(unsubscribe => { console.log('Unsubscribed Results => ', unsubscribed)})
.catch(err => console.log(err))
Console prints
Unsubscribed Results => undefined