Reputation: 3
When you make a request to an API, the operation is usually asynchronous. I am wondering what actually makes these API requests asynchronous? Is it because we send the requests asynchronously(like using .then() function or async/await for promise) or the API server handles our requests asynchronously? I think it should be the former one? Besides, why some functions can be asynchronous without promise(such as setTimeout() and fs.readFile())?. Thanks!
Upvotes: 0
Views: 171
Reputation: 169398
setTimeout()
uses "old-school" callback-style asynchronicity, and fs.readFile()
uses Node.js's own brand of callback asynchronicity, where by convention the first argument of the callback is an error, if any occurred.
new Promise()
, or util.promisify
in Node.js.Upvotes: 1