Skip to content
Advertisement

Tag: promise

TypeError: fs.createReadStream is not a function

I prefer to use promises rather than callbacks so I’ve used util.promisify. I’ve received TypeError: fs.createReadStream is not a function at const attachments = {attachment: fs.createReadStream(‘kitty.png’)}; line. How can I solve that? Answer fs.promises is not a superset of fs. While it replaces some methods on fs with methods of the same core name that return a promise, it does

Javascript: Error in Promise implementation

I’m trying to perform async function and then console log the results with the help of Promise. I’m afraid I haven’t quite grasped the concept yet. I wanted to wait till getlinks finished performing tasks and then console log the result. But the it logs the result as empty even before the getlink is finished. Answer The simplest answer is

Where to place async/await in this case?

EDIT: The problem was not the placement of the async/await per se, but the fact that I was trying to make a constructor asynchronous. I have looked through docs, read other questions and answers, but I still can’t get my head wrapped around what function to make async, and where to place the await, to get the behaviour that I

How does Promise Chaining work in memory?

Console Output: My main question is what is actually happening when the global execution context thread is finished and popped of the execution stack. How does JS/V8 know where this Promise Object is in memory if the Promise Object is not assigned to a variable within global execution context? How does it know where to update the promise value and

Questions on performance regarding async/await vs Promises and the event loop

Introduction A colleague of mine and I have been discussing the asynchronous nature of JavaScript in the browser and wondering what technical benefits are. We are aware that async/await is syntactical sugar for Promises, but curious to know if there is any other performance benefit for using one over the other. For example: Are both async/await and Promises treated the

How can I retry function?

I’m developing a script for personal needs. I need to retry if an error returned, but I don’t know how to fix it. how to resolve it? But I get the following error: TypeError: You may only yield a function, promise, generator, array, or object, but the following object was passed: “[object Object]” Answer You can do it very generally

Advertisement