Is this possible in Typescript? I want to turn e.g. something like this: Into this: I want to use it to resolve an object with promises as values, but still stay type safe. In this example, I need to convert IPromiseObject to an object with the same keys but the values resolved so that I can use it as return
Tag: promise
Perform an action after a promise.then callback
I’m trying to encapsulate some intialization / clean up code in a single Promise. What I want if to execute some code, execute the then and then execute some more code. This is what I came up with: which gives me the following output in the terminal: All good so far. However, when we make the callback async, it no
How to return a Promise in a Javascript async function? Why does Async method not wrap the returned Promise?
I have the following code. My intention is to start a task (which involves a few await calls before it can actually start). When it finishes starting it, I need to update the UI to tell user that the task has started and is waiting for result. Result will come in later so I want to return another Promise so
If an empty Promise is encountered within an infinite while loop, why is the while loop resolved with a pending Promise?
If I make a Promise that is never fulfilled: const nothingPromise = new Promise((resolve) => {}); And then I await that Promise within an infinite while loop: async function run() { while (true) { await nothingPromise;}} Any then() function attached to the function will not run, but I don’t get an infinite loop either. I get a pending Promise. In
Node.js/Axios/Cheerio Web Scraping – issue with Promises
I have an issue with part of my web scraping program. The return res.send(statsArray) line in index.js always returns an empty array on the initial run (using npm start), and will only return a properly filled array after at least one refresh. Here is relevant index.html (if needed): Here is my app.js, the file linked by index.html: Here is the
Resolving a promise to multiple parameter values
Is it possible to resolve a promise in such a way that the next promise in the chain can be an executor that takes multiple parameters? For example, say I have a function that takes three parameters: If I’m including it in a chain, e.g. one of these: Is there something I can return (in place of /* ??? */)
How to catch Firebase promise in React?
I have a simple function that checks if the user has Premium access or not: I tried to catch this in various ways, but no luck, it always returns an “undefined” object. What is the correct way to get the returned Boolean value? Answer onSnapshot is meant for listening to a collection continuously, getting repeatedly notified as its value changes.
How can I update a state variable from a promise?
I am trying to determine if a customer has an active subscription or not. To do this I am utilizing the following code: I have been able to successfully get all of my other functions where I am doing the comparisons for if a user is a subscriber but where I am having an issue is updating the state value
How can variable be used in promise chaining before declaration?
I came across the following code while working with promises. And it works correctly. I have read shallowly on how async/await code is run on node. But, in the following code, how is the session variable accessible inside the .then() function? Is it just by sheer chance that this code works or is there something about how node runs async/await
Retrieve value from IndexedDB using Dexie and Svelte
I don’t understand how I can get a value from IndexedDB using Dexie. Database is all good in ‘application’ tab in inspect tool. Total newbie, so please be understanding. My db.js App.svelte Whatever I try, object with daysMax={total} outputs undefined, [object Object] or something like [Dexie object Object]. I just want to get 20 from db, as seen in db.js: