You may tempted to use node-fibers or a module derived from it, but node fibers can only wrap async function call into a sync function inside a fiber. You were also told for backward compatibility, getData API cannot be changed to return merely a promise or demand a callback parameter. One day you were told to switch the underlying data source to a repo such as MongoDB which can only be accessed asynchronously. It's obvious both getData and fs.readFileSync are sync functions. ![]() Under the hood data is saved in a file so you implemented getData using Node.js built-in fs.readFileSync. Suppose you maintain a library that exposes a function getData. ![]() DeAsync turns async function into sync, implemented with a blocking mechanism by calling Node.js event loop at JavaScript layer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |