How to use the forEachOf function from async

Find comprehensive JavaScript async.forEachOf code examples handpicked from public code repositorys.

1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
* @example
*
* var obj = {dev: "/dev.json", test: "/test.json", prod: "/prod.json"};
* var configs = {};
*
* async.forEachOf(obj, function (value, key, callback) {
*     fs.readFile(__dirname + value, "utf8", function (err, data) {
*         if (err) return callback(err);
*         try {
*             configs[key] = JSON.parse(data);
fork icon0
star icon2
watch icon1

177
178
179
180
181
182
183
184
185
186
  })
},

readSensors : ()=>{

  async.forEachOf(Automation.sensor,(s,key,next)=>{
    Automation.getSensorValue(key,(response)=>{
      Automation.sensor[key].value = response.data;
      if(!response.error)
        ws.reportSensor(client,key,response.data)
fork icon0
star icon0
watch icon0

+ 7 other calls in file

140
141
142
143
144
145
146
147
148
149
if (err) {
  return next(err);
}

// Iterate through each action.
async.forEachOf(actions, (action, index, done) => {
  if (actions[index].initialize) {
    actions[index].initialize(method, req, res, done);
  }
  else {
fork icon0
star icon0
watch icon1

691
692
693
694
695
696
697
698
699
700

// Deprecated API-----------------------------------------
Get_Hotels: async (req, res) => {

    let HotelData = await Hotel.find({}).sort("createdAt DESC");
    async.forEachOf(HotelData, function (value, i, callback) {
        HotelData[i].bde_name = '';
        if (value.bdeId && value.bdeId != '') {
            User.findOne({ select: ["userId", "firstname", "lastname"] }).where({ userId: value.bdeId }).exec(function (err, UserData) {
                if (UserData) {
fork icon0
star icon0
watch icon1

+ 12 other calls in file

181
182
183
184
185
186
187
188
189
190
let userId = req.body.userId;
if (!req.body.userId) {
    return res.send({ responseCode: 201, msg: 'Please provide user ID to fetch user bids' });
}
let BidsAll = await Bids.find({ userId: userId }).sort("createdAt DESC");
async.forEachOf(BidsAll, function (value, i, callback) {
    if (value.hotel_id) {
        Hotel.findOne({ select: ['id', 'image'] }).where({ id: value.hotel_id }).exec(function (err, HotelData) {
            if (HotelData) {
                BidsAll[i].hotel_image = HotelData.image;
fork icon0
star icon0
watch icon0

+ 3 other calls in file