node.js - how to control nodejs webpush in forEach -
i sending chrome notification via web-push nodejs
in foreach
, , updating log table in callback. happens last record updating records. how control this. here code
records.foreach(function (record) { var msgd = queuerecords[nc].message.split('####'); var payloadmessage = ""; if (arrsubscribedetails[bc].source == "desktop") { // desktop payloadmessage = msgd[0] + '####' + msgd[2] + '####' + msgd[3] + '####' + msgd[4]; apptype = 10; } else { // wap payloadmessage = msgd[1] + '####' + msgd[2] + '####' + msgd[3] + '####' + msgd[4]; apptype = 1 } notitype = msgd[5]; webpush.sendnotification(arrsubscribedetails[bc].endpoint, { ttl: 345600, payload: payloadmessage, userpublickey: arrsubscribedetails[bc].publickey, userauth: arrsubscribedetails[bc].authenticationkey, }, function (subsdet) { var vartimestamp = objcommon.mongotime(); var objectlogtable = new global.logtable(); objectlogtable.matriid = queuerecords[nc].matriid; objectlogtable.dateupdated = vartimestamp; objectlogtable.apptype = apptype; objectlogtable.notitype = notitype; objectlogtable.status = jsonobject["responsecode"]; insertlogtable(objectlogtable); if (objectlogtable.status != 201) { var fieldname = 'subscribedetails.' + bc + '.status'; var fieldvalue = 1; var queryupdate = {}; queryupdate[fieldname] = fieldvalue; updatebrowsernotificationtable(queuerecords[nc].matriid, json.parse(json.stringify(queryupdate))); } bc++; callback(splitbrowsers(function (notificationdet) {}, arrsubscribedetails, queuerecords, nc, bc)); }); });
wiki
Comments
Post a Comment