title: High Delay in FCM when sent through Firebase Functions
body: <p>I'm trying to send FCM using Firebase Functions, This is the code I'm using   </p>
  
  <pre><code>'use strict';
  const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  admin.initializeApp();
  admin.firestore().settings({
  timestampsInSnapshots: true
  });
  var token = 'token_value';
  var sender = 'sender_value';
  var reciever = 'reciever_value';
  var message = 'message_value';
  var payload ='payload_value';
  var db = admin.firestore();
  
  
  
  
  exports.sendFollowerNotification = 
  functions.database.ref('/m/{messageid}')
     .onCreate((snapshot, context) =&gt; {
        console.log('v21');
        message = context.params.messageid;
        console.log('Message Id:', message);
  
        reciever = snapshot.val().r;
        console.log('Message reciever: ', reciever);
        sender = snapshot.val().s;
        console.log('Message sender: ', sender);
                  payload = {
                      data: {
                          id: `${message}`,
                          sender: `${sender}`
                      }
  
  
                  };
        console.log('Payload Created');
  
  
  
      var tokenRef = db.collection(reciever).doc('t');
      console.log('Fetching Token');
      tokenRef.get()
          .then(doc =&gt; {
              console.log('Fetching Token started'); 
              if (!doc.exists) {
                  console.log('Token doesnt exist ');
              } else {
                  token = doc.data().v;
                  console.log('Token data:', token);
  
              }
              console.log('End Then');
              return token;
  
          })
          .catch(err =&gt; {
              console.log('Error getting token', err);
          }).then((token) =&gt; {
              console.log('Sending FCM now');
              admin.messaging().sendToDevice(token,payload);
              return console.log('Successfully sent message:');
          })
          .catch((error) =&gt; {
              console.log('Error sending message:', error);
          });
  
  
  
  })
  </code></pre>
  
  <p>The problem is that FCM is received with huge delay(about 40s), however fcm sent from Firebase Console is received almost immediately (about 2-3s).
  Since I am an android developer and have no experience of Node.js, I believe that something is wrong with JS code. Help me by telling whats wrong or possible workaround.</p>