Node.js如何在异步方法都执行后再执行

福尔摩斯对我笑 2018-11-28 64344 次 11485条

参考链接:https://blog.csdn.net/duzixi/article/details/53842182

f.on("ready", function()
{
console.log("ready");
files.forEach( (elem,index) =>
{
var action = ()=>{
return new Promise( (resolve,reject )=>{

f.get('/www/pdf/msds/'+elem, function(err, stream){
if(err)
{
f.put(offlineFile +'\\'+elem, '/www/pdf/msds/'+elem, function (err) {
if (err) reject("文件上传出错:" + offlineFile + err);
console.log("成功新增");
resolve("新增");
})

}else
{

f.put(offlineFile +'\\'+elem, '/www/pdf/msds/'+elem, function (err) {
if (err) reject("文件上传出错:" + offlineFile + err);
console.log("成功覆盖");
resolve("覆盖");
})
}
})



})
}

actions.push(action()); //将每次循环调用的方法保存到数值
})

//数值中所有方法执行完毕后,调用
Promise.all(actions).then( (result)=>{
console.log(result)
f.end();
}).catch((error)=>{
console.log(error)
})
let arr = [1,2,3,4,5];

        (async () => {
            for (let i=0; i<arr.length; i++) {
                console.log(i);
                await fn();
            }
        })();

        arr.forEach( async v => {
            console.log(v);
            await fn();
        } );

        (async () => {
            for (let i of arr) {
                console.log(i);
                await fn();
            }
        })();
        
        function fn() {
            return new Promise( resolve => {
                setTimeout(() => {
                    console.log('...');
                    resolve();
                }, 1000);
            } );
        }
标签: 无

非特殊说明,本博所有文章均为博主原创。

头像也是LOGO
未来博客 博主大人
到了这个年纪,不应该再彷徨!

发表评论



 


已有 11485 条评论 1


  1. longchamp outlet

    Thank you so much for giving everyone an extraordinarily remarkable chance to discover important secrets from here. It is always very great plus jam-packed with a great time for me personally and my office acquaintances to visit your site more than thrice per week to learn the new things you have got. Not to mention, I am also always fascinated with all the dazzling secrets served by you. Some 1 areas in this article are in truth the most beneficial we have had.

    回复 2019年10月28日
  2. golden goose sneakers

    Needed to send you one bit of word just to thank you very much yet again with your incredible secrets you have shown in this article. This is so strangely open-handed of people like you to make easily what most people would’ve offered for an ebook to earn some profit for their own end, especially considering that you might well have done it in case you wanted. The ideas also acted to be the easy way to understand that most people have a similar fervor the same as mine to realize a little more when considering this condition. I think there are some more pleasant occasions up front for folks who see your website.

    回复 2019年10月27日
  3. yeezy shoes

    I precisely wished to thank you very much once again. I do not know the things that I could possibly have tried in the absence of the actual methods provided by you regarding this theme. It actually was a very terrifying scenario in my view, however , spending time with your expert form you handled that forced me to cry for gladness. I am just happier for this advice and even sincerely hope you recognize what an amazing job that you’re carrying out instructing many others through a site. More than likely you have never encountered any of us.

    回复 2019年10月27日
  4. kobe sneakers

    I would like to convey my love for your kind-heartedness giving support to individuals that really want guidance on the subject. Your special commitment to passing the message all through had been remarkably invaluable and have continually enabled many people like me to attain their endeavors. This useful tips and hints denotes much a person like me and substantially more to my office colleagues. With thanks; from each one of us.

    回复 2019年10月27日
  5. golden goose sneakers

    Thank you so much for providing individuals with an extremely brilliant chance to read critical reviews from here. It is often very terrific plus jam-packed with amusement for me and my office peers to visit the blog at the very least thrice per week to read through the newest things you will have. And indeed, I’m just always pleased for the astonishing advice you give. Some 1 ideas on this page are rather the most efficient we have all had.

    回复 2019年10月27日
  6. fila shoes

    Thanks so much for giving everyone an extraordinarily breathtaking possiblity to read articles and blog posts from this site. It is usually very useful and also jam-packed with a great time for me and my office acquaintances to visit the blog at minimum 3 times in a week to read the new tips you have got. And of course, I’m so certainly fascinated with your astounding advice served by you. Some two ideas in this post are indeed the very best we have all ever had.

    回复 2019年10月26日
  7. hermes birkin

    I am glad for writing to let you understand what a wonderful encounter my friend’s daughter went through browsing your webblog. She learned numerous issues, which include how it is like to have an excellent helping mindset to make other individuals without hassle completely grasp certain advanced topics. You actually did more than readers’ expected results. Thank you for producing these good, dependable, educational and even unique tips about that topic to Gloria.

    回复 2019年10月26日
  8. birkin bag

    Thanks so much for giving everyone such a nice opportunity to read from this blog. It is usually very brilliant and also full of fun for me and my office peers to search your blog nearly thrice in one week to find out the latest things you have. Of course, I am actually fascinated with the fabulous tips and hints served by you. Certain 2 ideas in this posting are undeniably the best we’ve ever had.

    回复 2019年10月26日
  9. birkin bag

    I intended to send you one very little observation to be able to thank you as before over the nice suggestions you have discussed in this article. It’s really tremendously open-handed of you to present publicly all that many individuals could have supplied for an e-book to help with making some dough for themselves, especially considering that you could possibly have tried it in case you considered necessary. The things likewise worked as the easy way to comprehend other individuals have a similar fervor much like my very own to know good deal more regarding this issue. I’m sure there are many more pleasurable instances ahead for individuals that read carefully your website.

    回复 2019年10月26日
  10. golden goose

    I as well as my pals appeared to be digesting the great tactics on your web site and so suddenly got a horrible feeling I had not expressed respect to the web site owner for them. The men had been very interested to learn all of them and now have quite simply been tapping into those things. Appreciate your being very thoughtful and also for finding such remarkable subject matter most people are really wanting to know about. My very own sincere apologies for not expressing appreciation to you sooner.

    回复 2019年10月25日
  11. yeezy

    I am commenting to let you understand what a awesome encounter my daughter developed checking your web page. She noticed lots of issues, which include how it is like to possess a great helping style to let other folks without difficulty know just exactly a number of tortuous issues. You truly did more than people’s desires. Many thanks for producing the warm and helpful, healthy, explanatory and in addition easy tips on your topic to Julie.

    回复 2019年10月25日
  12. kyrie 3

    My spouse and i felt so more than happy Louis could complete his investigations from the ideas he obtained when using the site. It is now and again perplexing to simply choose to be giving freely facts which often many people could have been selling. And we all keep in mind we have got the website owner to thank for that. The type of explanations you have made, the easy blog menu, the friendships you will make it possible to promote – it’s got most impressive, and it’s really letting our son in addition to our family consider that the article is excellent, which is rather important. Many thanks for the whole thing!

    回复 2019年10月25日
  13. curry 4

    Thanks a lot for giving everyone an extraordinarily breathtaking chance to read in detail from this site. It really is very fantastic and jam-packed with amusement for me and my office colleagues to search your site at minimum thrice in one week to find out the new stuff you have. And of course, we are actually happy with all the perfect points served by you. Some 1 facts in this posting are particularly the most beneficial we have ever had.

    回复 2019年10月25日
  14. retro jordans

    I and also my friends have been checking the nice points on your web page then all of a sudden I got a horrible suspicion I never expressed respect to the site owner for those strategies. All of the guys appeared to be consequently warmed to see all of them and have in effect clearly been using these things. Thanks for truly being quite helpful and also for obtaining these kinds of nice subject matter most people are really desperate to discover. My personal sincere regret for not expressing gratitude to sooner.

    回复 2019年10月24日
  15. curry 5

    I wanted to write down a simple note to be able to say thanks to you for those precious guidelines you are placing on this website. My time consuming internet research has at the end of the day been honored with good quality facts and techniques to go over with my neighbours. I would declare that we website visitors actually are definitely lucky to dwell in a good community with so many brilliant professionals with helpful basics. I feel very much blessed to have used your entire web pages and look forward to really more enjoyable times reading here. Thanks a lot again for all the details.

    回复 2019年10月24日
  16. balenciaga shoes

    I’m writing to make you be aware of what a brilliant experience my princess obtained checking the blog. She even learned such a lot of details, with the inclusion of what it is like to have an incredible coaching mood to let many people without difficulty learn various specialized matters. You undoubtedly exceeded readers’ expected results. I appreciate you for offering the priceless, dependable, educational and in addition unique tips about the topic to Evelyn.

    回复 2019年10月24日
  17. nike air max 95

    I together with my guys happened to be studying the nice tricks from your website then the sudden got a terrible suspicion I had not thanked the site owner for them. Most of the ladies had been as a consequence very interested to read all of them and have in effect clearly been enjoying them. Appreciation for being well thoughtful as well as for having such extraordinary issues millions of individuals are really eager to be informed on. Our sincere apologies for not saying thanks to sooner.

    回复 2019年10月24日
  18. nike air max 97

    I intended to post you that little bit of word just to say thanks a lot again for those amazing ideas you’ve shown on this site. This is certainly seriously open-handed of you to offer easily what exactly a number of people could have offered for an ebook to generate some profit on their own, even more so given that you could have done it if you wanted. These tricks also worked to become a good way to recognize that the rest have a similar zeal just like my personal own to find out whole lot more on the subject of this problem. I believe there are numerous more pleasant times in the future for individuals who read your blog.

    回复 2019年10月23日
  19. supreme new york

    I wanted to construct a simple message in order to say thanks to you for all the remarkable tactics you are showing at this site. My extensive internet look up has at the end been recognized with excellent strategies to exchange with my company. I would believe that most of us website visitors are extremely endowed to exist in a decent network with many brilliant individuals with insightful solutions. I feel very much blessed to have seen your entire web page and look forward to plenty of more fun minutes reading here. Thank you once again for all the details.

    回复 2019年10月23日
  20. nike shox for women

    I precisely needed to say thanks again. I’m not certain the things I could possibly have gone through in the absence of the type of techniques shown by you directly on my field. It has been a real fearsome matter for me, however , taking a look at a specialized mode you resolved the issue forced me to weep over contentment. I will be happier for the advice and trust you are aware of an amazing job you happen to be undertaking training the others using your blog post. Most probably you’ve never got to know all of us.

    回复 2019年10月22日
  21. air jordan

    I wanted to write you the very small note to thank you very much the moment again for all the superb opinions you have documented on this page. This is so incredibly generous of people like you to present without restraint what many of us would’ve marketed as an ebook to generate some money for their own end, certainly considering the fact that you could possibly have done it if you ever decided. Those smart ideas also served to become a easy way to be aware that some people have the same dreams much like my very own to see many more on the topic of this problem. I know there are lots of more pleasurable instances ahead for individuals who see your site.

    回复 2019年10月21日
  22. balenciaga trainers

    I simply wanted to compose a note in order to thank you for all of the unique tips and hints you are writing at this site. My particularly long internet search has now been rewarded with wonderful tips to share with my great friends. I would repeat that most of us readers are definitely endowed to dwell in a very good place with many special individuals with great tips. I feel rather grateful to have come across your entire webpages and look forward to really more entertaining times reading here. Thank you again for a lot of things.

    回复 2019年10月20日
  23. air jordan

    I want to express thanks to the writer for rescuing me from such a scenario. Right after exploring throughout the world wide web and getting ideas that were not beneficial, I figured my entire life was gone. Living without the presence of answers to the problems you have solved as a result of your good short post is a serious case, and ones which may have in a negative way damaged my entire career if I hadn’t noticed the blog. The mastery and kindness in controlling every aspect was very useful. I’m not sure what I would have done if I hadn’t come upon such a point like this. I can also at this point look ahead to my future. Thank you very much for your professional and result oriented help. I won’t think twice to endorse your blog to anybody who ought to have support on this topic.

    回复 2019年10月19日
  24. bape clothing

    A lot of thanks for all your effort on this web site. My niece takes pleasure in working on investigations and it’s really simple to grasp why. My partner and i notice all concerning the lively form you produce very important steps on the web site and as well increase response from people on that area while our favorite simple princess is always understanding so much. Take advantage of the remaining portion of the new year. You have been conducting a dazzling job.

    回复 2019年10月18日
  25. air max 90

    I wish to express thanks to this writer for bailing me out of such a setting. Just after surfing around through the search engines and seeing principles that were not powerful, I thought my life was gone. Living without the approaches to the issues you have resolved all through this post is a serious case, as well as those that would have in a wrong way damaged my career if I hadn’t come across your web site. Your own personal know-how and kindness in dealing with everything was helpful. I don’t know what I would’ve done if I had not come upon such a step like this. I’m able to at this point look ahead to my future. Thanks a lot so much for your professional and effective guide. I will not hesitate to recommend the blog to anybody who should have recommendations about this subject matter.

    回复 2019年10月17日
  26. yeezy boost

    My husband and i were so fulfilled when Jordan could complete his web research because of the precious recommendations he got in your web pages. It’s not at all simplistic just to be offering guidelines that many many others may have been trying to sell. And now we keep in mind we have got the website owner to give thanks to because of that. The main explanations you have made, the easy website menu, the relationships you will make it possible to foster – it’s got everything powerful, and it is letting our son in addition to our family reason why that theme is brilliant, which is extraordinarily serious. Many thanks for all the pieces!

    回复 2019年10月16日
  27. nike outlet

    I wanted to compose a note to appreciate you for these fabulous recommendations you are writing on this website. My time intensive internet research has now been recognized with extremely good knowledge to go over with my good friends. I would believe that many of us site visitors are unquestionably fortunate to exist in a fantastic place with so many outstanding individuals with insightful suggestions. I feel pretty privileged to have encountered your website and look forward to tons of more excellent moments reading here. Thank you once again for a lot of things.

    回复 2019年10月15日
  28. jordan shoes

    I truly wanted to send a brief remark so as to say thanks to you for all of the magnificent concepts you are giving out here. My extended internet search has finally been honored with excellent facts to go over with my pals. I would assume that many of us visitors are unequivocally fortunate to live in a wonderful website with very many awesome individuals with insightful things. I feel very much fortunate to have used your entire webpages and look forward to so many more pleasurable minutes reading here. Thanks again for all the details.

    回复 2019年10月14日
  29. yeezy boost

    I in addition to my pals appeared to be looking at the best information and facts on your site and so instantly got a terrible feeling I had not thanked the web site owner for those secrets. The guys were definitely as a result stimulated to read through them and have now surely been tapping into those things. Thank you for indeed being considerably thoughtful as well as for picking out this sort of essential subjects most people are really eager to discover. My personal sincere apologies for not saying thanks to you earlier.

    回复 2019年10月14日
  30. jordan shoes

    Thanks a lot for giving everyone such a superb chance to check tips from this site. It is always very cool and as well , packed with amusement for me and my office mates to visit your site more than three times weekly to find out the latest stuff you have. Of course, I’m so at all times happy for the exceptional points you serve. Selected 4 tips in this posting are in fact the best we’ve ever had.

    回复 2019年10月13日
  31. fila sneakers

    I am just writing to make you be aware of of the magnificent experience my daughter enjoyed reading your site. She noticed a good number of details, not to mention how it is like to have a marvelous helping mindset to have folks quite simply know a number of multifaceted topics. You truly did more than visitors’ desires. Thank you for displaying such powerful, healthy, explanatory and in addition easy guidance on your topic to Kate.

    回复 2019年10月12日
  32. yeezy boost 350

    Thanks so much for providing individuals with an exceptionally wonderful chance to check tips from this site. It’s always so superb plus packed with a lot of fun for me personally and my office co-workers to search your site on the least three times per week to find out the fresh items you will have. And of course, I’m so usually astounded with all the brilliant tips you serve. Certain 4 tips on this page are completely the best I have had.

    回复 2019年10月11日
  33. longchamp handbags

    I want to convey my affection for your generosity for those who absolutely need guidance on in this concept. Your special commitment to passing the message up and down came to be exceptionally good and has made many people much like me to attain their endeavors. Your new interesting guide can mean a whole lot to me and substantially more to my office colleagues. Thanks a ton; from everyone of us.

    回复 2019年10月10日
  34. golden goose outlet

    I have to show my respect for your kindness supporting visitors who need assistance with in this concept. Your real commitment to getting the solution all over became rather effective and have frequently helped ladies much like me to realize their endeavors. The warm and helpful tutorial signifies a whole lot a person like me and far more to my mates. With thanks; from all of us.

    回复 2019年10月9日
  35. off white

    I am glad for commenting to make you understand of the perfect experience my wife’s daughter enjoyed visiting your web site. She came to find several pieces, which include how it is like to have an awesome teaching spirit to let many more very easily master a variety of very confusing subject areas. You undoubtedly did more than visitors’ expected results. Many thanks for providing those invaluable, trustworthy, edifying and even easy tips on the topic to Emily.

    回复 2019年10月8日