Skip to content

Instantly share code, notes, and snippets.

@mulderp
Created October 18, 2013 17:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mulderp/7045228 to your computer and use it in GitHub Desktop.
Save mulderp/7045228 to your computer and use it in GitHub Desktop.
nested promises
function allMovies() {
return client.smembersAsync('movies.ids').then(function(ids) {
var movies = _.map(ids, function(id) {
return client.hmgetAsync("movies:" + id, 'title', 'description', 'director', 'year').then(function(data) {
return {
title: data[0],
description: data[1],
director: data[2],
year: data[3]
};
});
});
return Promise.all(movies);
});
@agatsoh
Copy link

agatsoh commented Feb 9, 2016

Hi mulderp I am new to writing Promises and hence came across your question. I want to ask you does
client.smembersAsync('movies.ids') this function return a Promise Object or is it just a normal function. Can you call .then() on normal functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment