classroom icon indicating copy to clipboard operation
classroom copied to clipboard

异步 callback 调用获得返回值

Open billie66 opened this issue 11 years ago • 5 comments

有人建议用 async.js 或 Q

http://dev.oupeng.com/articles/7-tips-for-a-nodejs-padawan

billie66 avatar Jun 04 '14 12:06 billie66

http://stackoverflow.com/questions/6847697/how-to-return-value-from-an-asynchronous-callback-function

happypeter avatar Jun 04 '14 13:06 happypeter

因为是异步,写在前面的语句未必就先执行,所以会造成有时候数据库还没存好,就开始读取了,造成了读取失败。

happypeter avatar Jun 04 '14 13:06 happypeter

http://justinklemm.com/node-js-async-tutorial/ 正好是说上面这个问题的,看来得用 async.js

happypeter avatar Jun 04 '14 13:06 happypeter

https://medium.com/tech-talk/e7c0b0e5ce3c

billie66 avatar Jun 04 '14 13:06 billie66

上面这个 patch 中又 async.js 使用的时候 callback() 位置的一个 tip

happypeter avatar Jun 05 '14 00:06 happypeter