logo
down
shadow

Promise is not working correctly with Firebase


Promise is not working correctly with Firebase

By : user2176181
Date : October 14 2020, 02:22 PM
I hope this helps . When Promise.all() is called in your code the promises array is still empty because firebase.database().ref('node-client/images').once('value') returns a Promise which is resolved after the database has been queried successfully.
Try calling Promise.all() after the array has been filled completely:
code :
let promises = [];
//Return first promise from DB save to zone_obj list
firebase.database().ref('node-client/images').once('value').then(function(snapshot) {
    // Push the promises to the array
    promises.push(snapshot.val());
})
.then(function() {
    // Log the values when all promises are resolved
    Promise.all(promises).then(values => {
        console.log(values); // zone_obj
    });
});


Share : facebook icon twitter icon
Why is this Promise not working correctly?

Why is this Promise not working correctly?


By : user2614892
Date : March 29 2020, 07:55 AM
I hope this helps you . Move the //code here is being executed before the dialog is even shown to here:
code :
var sameActivityCnt = $(actId).length;
if(sameActivityCnt){
  sameActivityDialog().then(function(retVal) {
    if (retVal === true){
      activityid += "-"+sameActivityCnt++;
    }

    // code goes here!!!!

  });
}
var sameActivityCnt = $(actId).length;
sameActivityDialog().then(function(retVal) {
  if(sameActivityCnt && retVal === true){
    activityid += "-"+sameActivityCnt++;
  }

  // code goes here!!!!

});
var promise = sameActivityDialog();
var sameActivityCnt = $(actId).length;

if(sameActivityCnt){
  promise = promise.then(function(retVal) {
    if (retVal === true){
      activityid += "-"+sameActivityCnt++;
    }
    return retVal;
  });
}

promise = promise.then(function(retVal) {
  // code goes here!!!!
  return retVal;
});
function doIf(condition, fn) {
  return function(data) {
    if (condition) {
      return fn(data);
    } else {
      return data
    }
  };
}

function appendID(retVal) {
  if (retVal === true){
    activityid += "-"+sameActivityCnt++;
  }
  return retVal;
}

function doMoreStuff(retVal) {
  // code goes here!!!!
  return retVal;
}

var sameActivityCnt = $(actId).length;

sameActivityDialog()
  .then(doIf(sameActivityCnt, appendID))
  .then(doMoreStuff);
Callback/promise not working correctly

Callback/promise not working correctly


By : Tony Wilkinson
Date : March 29 2020, 07:55 AM
Hope that helps Deferred allows you to make asynchronous operations. To that end enclose your inner function inside a setTimeout to fully mimic an async operation:
code :
function makeDiv(callback){
    var dfd = jQuery.Deferred();
    setTimeout(function() {
        $("#full_complete").append($(dose_credit).html()+ " " +$(storyboard).html() + " " +$(nar_name).html() + " " +$(nar_text).html());
        full = $(this).closest('div').find("#full_complete");
        dfd.resolve( "hurray" );
    }, 0);
     return dfd.promise();
}
function makeDiv(callback){
    var dfd = jQuery.Deferred();
    setTimeout(function() {
        dfd.resolve( "hurray" );
    }, 0);
     return dfd.promise();
}

makeDiv().then(function(result) {
  console.log(result); //hurray
  $("#full_complete").append($(dose_credit).html()+ " " +$(storyboard).html() + " " +$(nar_name).html() + " " +$(nar_text).html());
  full = $(this).closest('div').find("#full_complete");
});
function async(){
    var dfd = jQuery.Deferred();
    setTimeout(function() {
        dfd.resolve();
    }, 0);
     return dfd.promise();
}

async().then(function() {});
Firebase : firebase.Promise<any> compatibility with Rxjs Promise<any>

Firebase : firebase.Promise<any> compatibility with Rxjs Promise<any>


By : Diogo Techera
Date : March 29 2020, 07:55 AM
seems to work fine I'm trying to convert a firebase.Promise into an Observable using a project generated by angular-cli. , In TypeScript you can use type casting:
code :
let promise = firebase.whatever();
Observable.fromPromise(<Promise<any>>promise);
Promise.all not working correctly with array of Mongo Queries

Promise.all not working correctly with array of Mongo Queries


By : D_Chawk
Date : March 29 2020, 07:55 AM
wish helps you You are not using Promises but callbacks...
This is the correct way:
code :
for (let index = 0; index < obj.recommendedRoutes.length; index++) {
  console.log('Pushed: ' + index);
  promiseArr.push(
    User.find({
      _id: obj.recommendedRoutes[index].userId,
    }).then((data) => {
      obj.recommendedRoutes[index].userObj = data[0].toObject();
      console.log('Completed: ' + index)
    }, err => console.log('Database error: ' + err))
  );
}
Promise not working as expected while writing data to firebase

Promise not working as expected while writing data to firebase


By : akshay
Date : March 29 2020, 07:55 AM
I wish this helpful for you I am writing data to firebase using a loop and async function. I am using promises to get the result of query and want to display success message when all of data is inserted. I can not figure out what I am doing wrong. I know it has a small bug. Can anyone help me?
code :
uploadPromises.push(
      new Promise((resolve, success) => {
        ...
        db.collection("Parent").doc(uidstu).collection("Attendance").doc(f).set(attinfo).then(function () {
          console.log(attinfo);
          resolve();
        });
      })
    )
for (var j = 0; j < i; j++) {

        var naid = "name" + j + "";
        var na = document.getElementById(naid).innerHTML + "";

        var stid = "status" + j + "";
        var stat = document.getElementById(stid).value + "";

        var uidid = "uid" + j;
        var uidstu = document.getElementById(uidid).innerHTML + "";

        var attinfo = {
          student_Id: uidstu,
          student_attendanceValue: stat,
          student_class: clstd,
          student_name: na
        };

    uploadPromises.push(
      db.collection("Parent").doc(uidstu).collection("Attendance").doc(f).set(attinfo).then(function () {
          console.log(attinfo);
        });

    )

  }
Related Posts Related Posts :
  • Error while using "Protractor jasmine 2 screen shot reporter"
  • How to convert Node.js command line app to single executable?
  • How to make a GET URL request (same server)
  • How to pick date in any format from a string in node JS?
  • Node.js - Wait for function to finish, then process further
  • Why does express middleware override my api's response?
  • How to make something like remote method on loop-back middleware?
  • Sum with Calculation from Sub-Document items
  • Why nodejs restarts every time I refresh the page on the client side
  • Can i able to view my table design and contents in Sqlite?
  • Why is my interval function causing a memory leak in Node.js?
  • Use firebase with variable in the path
  • Routing to sub docs with express 4 and mongoose
  • Integrate passport.js from node server file to routes file
  • Invitation system using Passport JS
  • Facing issue in making rest api(Get) in nodejs
  • Deploying Vue app to Heroku, cannot find module shelljs
  • Disable warning message for eslint rule not being found
  • How to finish/kill Mocha/Istanbul test cycle with Node.js
  • TypeError: Cannot read property 'username' of undefined at updateUserList (<MY_PATH>\chatapp\socket\socket.js:34:2
  • EJS, node js forEach loop on include
  • node.js + oracledb - Interrupt ongoing query
  • Are all functions in the entry script for node js?
  • How to use Gun as an express route?
  • pug.compile() cannot find template files (res.render() can)
  • .htaccess Wordpress and NodeJS running alongside
  • SuggestedActions vs Keyboard in BotFramework?
  • Firebase function deploy error cannot find module firebase-admin
  • Nodemon is not recognized as an internal command operable program or batch file
  • Passing OSC messages between two computers over WAN via UDP and Node.js
  • Nodejs server https running, but socket won't connect (net::ERR_CONNECTION_TIMED_OUT)
  • How to No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘null’ is therefore not allo
  • how can I store cookies with node phantom?
  • Node js csrf token protection not working
  • How to handle a read and write in Cloud Functions Firestore
  • This document does not exist, it will not appear in queries or snapshots? Cloud Firestore
  • Unexpected result from assert.fail
  • Azure Functions and Node.js
  • Node sequelize group
  • Twilio node api: no video portion?
  • Create subsubdocs in Mongoose with Nested Schema
  • Quick Start (not so quick)
  • Dynamic named parameters in pg-promise
  • tsc is trying to resolve relative path modules in the wrong folder
  • issue with react-native: start script 'react-native-scripts start'
  • Firebase CLI - "Invalid project ID specified"
  • Mongoose - MissingSchemaError on population
  • node.js child_process spawn ignoring equal signs
  • Call a function with a Function object node.js
  • Property does not exist on a function's return value of multiple types
  • Facebook Messenger: How to send multiple messages with nodejs
  • Publish multiple Vuejs components in one project to npm using webpack
  • Multiple commands in package.json
  • nodejs input stream using express
  • How can I extract data as object not array from MongoDB using Node.js/Express?
  • How does the extension get the secret information about the build task in Team Foundation Server extension
  • How to develop two angular modules locally where module A imports module B
  • Slack Interact Only Once with Messages
  • How to get all table id's from bigquery without partitioning?
  • Send a function, module to main via object Function node.js
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org