Tuesday 3 May 2016

Promises Inside Promises...

Hey guys, I'm kind of stuck if I am doing this correctly.Basically, this is my redis setup: http://ift.tt/1QQeVDy have 3 keys labeled with games:*.My code: redis.keys('games:*').then(function(data){ return Promise.map(data, (gamename) => { return redis.get(gamename); }) }).then(function(data){ console.log(data) }); Which outputs: [ 'A MUFFIN!', 'A MUFFIN!', 'A MUFFIN!' ]Which is correct. But.. is this the correct way to do this? I love how bluebird makes it so much easier and I love the control flow. But I feel like I am doing something wrong. I don't know how to explain it.Does my final then always perform after the last redis.get call inside the`map'? Always? Or can some io bound / redis lag happen and return unwanted results? I just need to grasp my head around this async stuff, it feels like magic.

Submitted May 03, 2016 at 10:22AM by BillOReillyYUPokeMe

No comments:

Post a Comment