Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- request.getAsync("some.xml")
- .then( response =>
- //turn body into JSON
- xml2js.parseStringAsync( response.body )
- //assume it returns a nice array
- .then( result =>
- myMethod(result) )
- .then ( console.log("done") );
- /* DIDN'T WORK:
- function myMethod( param ){
- if ( param.length > 0 ){
- var oneThing = param.pop();
- //do an asynch operation like download... when done
- myMethod( param );
- //maybe return myMethod(param);
- }else{
- return true;
- }
- }
- */
- //========= UPDATED (works)
- function myMethod( list ){
- return Promise.all(list).each(function(item){
- return doOneItem(item);
- })
- }
- function doOneItem( item ){
- //returns a promise:
- return new Promise(function(resolve, reject){
- //async operation... ffmpeg().on('end') is when it's done
- //============================================= project implementation
- let cmd = ffmpeg(item.remotesource)
- .on('start', function(cmdline) {
- console.log('downloadStill/FLV: ' + cmdline);
- })
- .on('end', function(progress) {
- resolve("DONE"); //<----------NOTICE THIS LINE THOUGH
- })
- .on('end', function(issue) {
- reject("FFMPEG " + issue);//<----------NOTICE THIS LINE THOUGH
- })
- .save(item.localsource)
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement