Advertisement
phillipk

Untitled

Jan 23rd, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. request.getAsync("some.xml")
  2.  
  3. .then( response =>
  4. //turn body into JSON
  5. xml2js.parseStringAsync( response.body )
  6. //assume it returns a nice array
  7. .then( result =>
  8. myMethod(result) )
  9.  
  10. .then ( console.log("done") );
  11.  
  12. /* DIDN'T WORK:
  13. function myMethod( param ){
  14. if ( param.length > 0 ){
  15. var oneThing = param.pop();
  16. //do an asynch operation like download... when done
  17. myMethod( param );
  18. //maybe return myMethod(param);
  19. }else{
  20. return true;
  21. }
  22. }
  23. */
  24.  
  25. //========= UPDATED (works)
  26. function myMethod( list ){
  27. return Promise.all(list).each(function(item){
  28. return doOneItem(item);
  29. })
  30. }
  31.  
  32. function doOneItem( item ){
  33. //returns a promise:
  34. return new Promise(function(resolve, reject){
  35. //async operation... ffmpeg().on('end') is when it's done
  36.  
  37. //============================================= project implementation
  38. let cmd = ffmpeg(item.remotesource)
  39. .on('start', function(cmdline) {
  40. console.log('downloadStill/FLV: ' + cmdline);
  41. })
  42. .on('end', function(progress) {
  43. resolve("DONE"); //<----------NOTICE THIS LINE THOUGH
  44. })
  45. .on('end', function(issue) {
  46. reject("FFMPEG " + issue);//<----------NOTICE THIS LINE THOUGH
  47. })
  48. .save(item.localsource)
  49.  
  50. })
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement