JSFiddle - React, Tailwind, and code Playground

JavaScript

var pro = [];
function x() {
	pro.push(new Promise(function(done, fail) {
  	pro.push(new Promise(function(getUsersFromDbDONE, getUsersFromDbFAIL){
    	// Go to DB to search all the users that were logged using Twitter
      // It's Mongo, so, works using callback. here we have not a promise
      db.getUsers(function(allTheUsers) {
      	allTheUsers.forEach(function(user){
        	// for each user go to twitter a look for new tweets
          twitter.getTweetsFromUser(user).then(function(tweets){
          	if (theUserHasNewTweets) {
            	tweets.forEach(function(tweet){
              	pro.push(new Promise(function(saveNewTweetDONE, saveNewTweetFAIL) {
                  // callback again because we have no promise in MongoDB
                  db.saveTweets(tweets, function(){
                  	saveNewTweetDONE();
                  });
                }));
              });
            }
          });
        });
        getUsersFromDbDONE();
      })
    }));
    done();
  }));
}

Promise.all(pro).then(function(){
	db.closeConnection();
});