1

I have a json like this

{"queueDetails":
    [
        {
            "filepath":"video1.mp4",
            "format":{"Video":"mp4"},
            "formatpath":{"Video":"http://localhost/test"},
            "outputpath":{"Video":"D:/video/filename_video1.mp4"}
        },
        {
            "filepath":"video2.mp4",
            "format":{"Video":"mp4"},
            "formatpath":{"Video":"http://localhost/test"},
            "outputpath":{"Video":"D:/video/filename_video2.mp4"}
        },
    ]
}

Here I want to iterate over it, and I want to take the first array element and submit to the other function and wait for its status. When the first process is completed then I want to pick the next array element and do the same operation for the rest of the array's elements too.

How can we achieve this in node js?

How to implement a wait logic inside the iteration?

I'm aiming for a one by one operation by using this json.

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
Vishnu
  • 108
  • 9
  • https://stackoverflow.com/questions/37576685/using-async-await-with-a-foreach-loop – palaѕн Jan 25 '18 at 11:35
  • Is it possible to wait inside a for-each loop for a status change?or how can i put hold my array iteration until a status changes to true or some other value? – Vishnu Feb 12 '18 at 08:54

1 Answers1

0

You can use async.forEachLimit.

 async.forEachLimit(JSONArray, 1, function(singleObject, funCallback) 
       {
            //do your task with singleObject and than do funCallback
            //example call mongo query and then callback
             Collection.find(singleObject.id, function(err,dbResult) 
               {  
                 console.log(dbResult);
                 funCallback()
               });

        }, function() {
            console.log("complete");
        })
IftekharDani
  • 3,619
  • 1
  • 16
  • 21