title: how to handle array of 'promis'
body: <p>I built a database that contains a list of users who receive messages from firebase with a request key. Every time a new request with status 'open' inserted, I am trying to sort them all by the value of 'Timestamp' and send it by this order to the receivers(each receiver will get one message).
  if the list of receivers is empty I want to hold it, until another receiver will be added to the list and continue to the next request.
  I am not sure how to send each 'promise' separately one after another-</p>
  
  <pre><code>exports.notificationListener=functions.database.ref('requests')
  .onWrite(event=&gt;{
      const ref = event.data.ref;
      let requests= [];    
      var query=ref.orderByChild('TimeStamp');
  
      query.once('value',function(snap){
          snap.forEach(request=&gt;{
              if(request.val().Status==OPEN)  
                  requests.push(request.key);
          });
      });
      for (let key of requests) {
         return getOnlinReceiversToken().then(token=&gt;{
         let msg = {
          data: {
            source: key
                 }
           };
           return admin.messaging().sendToDevice(token, msg);
         )};
       }
   });
  
  function getOnlinReceiversToken() {
      let result = new Promise((resolve, reject) =&gt; {
       receiverRef.once('value', (snap) =&gt; {
        resolve(snap);
          }, 
         (err) =&gt; {
           reject(err);
        });
      });
      return result.then(snap =&gt; {
          snap.forEach(child =&gt; {
              if(child.Status == ONLINE){
                  let token = helper.getToken(child.key,db);
                  break;  
              }  
          });
          return token; 
      });
    }
  </code></pre>