I wasn't sure how to title this question.
What I am looking to do is grab a large array of movies, filter out only those that have reviews, then sort the reviews by date desc, then trim the list to grab only the latest 11 before setting the first entry to be featured and returning to the model then. With these numerous calls though, I notice some data being jumbled out of order and I believe it's due to all the calls running simultaneously. How can I use promises to structure this to wait for the previous step to complete before proceeding?
getLatestReviews(num) {
const movieList = this.getMovies();
const reviewList = movieList.filterBy('review');
const indexList = this.sortReviewsByDate(reviewList);
const latestList = this.getSetAmountOfMovies(num, indexList);
return this.setFirstReviewToFeatured(latestList);
},
What I'm experience is once I exceed 10 reviews the ordering starts getting out of whack and I believe it's due to the functions not running in a sequence. But I'm not sure how to use promises to ensure one step is complete before running the next.
Aucun commentaire:
Enregistrer un commentaire