5,294 questions
-4
votes
2
answers
88
views
How to reject a JavaScript promise with `TypeError` by calling the resolve function?
While reading the promise documentation I came across this statement:
If it's called with the same value as the newly created promise (the promise it's "tethered to"), the promise is ...
-1
votes
1
answer
74
views
What is wrong with this Promise.All code? [closed]
I have a page made up of multiple forms. Each form has it's own javascript file with a validate method like so.
function validateForm(){
return new Promise((resolve, reject) => {
...
0
votes
0
answers
65
views
Why does browser.tabs.sendMessage() not return a specific Error?
This question is about the Firefox API function:
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/sendMessage
Why does browser.tabs.sendMessage() not seem to return a ...
-1
votes
1
answer
42
views
How can I access the ${orderId} and ${payment} which is present in the method chaining of the promise to my last block of promise? [duplicate]
const cart = ["shoes","shirts","boxers","pants"]
function creatOrder(cart){
return new Promise((resolve,reject)=>{
if(!ValidateCart(cart)){
...
0
votes
0
answers
23
views
Custom React Hook to return memoized value. Async API call, having trouble returning the value and not the promise [duplicate]
So I am trying to build a custom react hook that fetches a value from an API and returns a string. However the issue I am running into is that it is returning a Promise and I am not sure how to ...
1
vote
1
answer
180
views
How can I enable Promise.try (Baseline 2025) in TypeScript?
Promise.try recently became available in Baseline 2025.
I wanted to know how can I enable this in a TypeScript project.
I'm currently using TypeScript 5.7.3 and have the following tsconfig.json:
{
&...
0
votes
0
answers
30
views
Allowed to pass undefined into Promise.all [duplicate]
Is it defined behaviour in JavaScript to pass undefined into Promise.all like so:
await Promise.all([fetchSomeData(), undefined])
What I want to achieve: execute a certain fetch only for ...
0
votes
0
answers
63
views
passing false to Promise.all [duplicate]
I've seen code like that and wonder how it works ? according to MDN Promise.allSettled expects an array of Promises but here it is passed false for one of them and seems to ignore it. Is this kind of ...
1
vote
1
answer
122
views
How to signal a view when pinia store is fully loaded?
We have a item view whose contents depends on a store with is loaded from a (rather slow) api. We found that the view is mounted before the store is fully loaded which is ok but how can a store ...
0
votes
3
answers
160
views
Await multiple promises in parallel, but return early if they take too long, once first 2 have resolved
I'm working with promises in JavaScript. I need to create three promises that each fulfill to a number. These conditions must be met:
The promises must be created synchronously, not one after the ...
0
votes
1
answer
90
views
Promise() as text in Label
considering:
function calculateDate(input) {
var result = something_this_takes_too_much_of_the_time * input;
}
Repeater {
count: 999
Label {
text: return (new Promise(resolve =&...
0
votes
1
answer
67
views
How to lazy load immediate functions
Before i start, i like to point out i am learnging JS, so this may be trivial, but having hard time do lazy load immidiate function https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.js
Example, I ...
4
votes
2
answers
93
views
Sequence of rejected promise with Promise.reject()
I am learning microtask queue and i have a simple question.
With the following code:
Promise.resolve().then(()=>console.log("Resolved1 Promise"));
Promise.reject().then(()=>console.log("...
0
votes
0
answers
57
views
catch on a Promise [duplicate]
I am new to Javascript and trying to understand how Promise really works. I understand basics of how chaining works in Promise.
Is version 1 equivalent to version 2.
How does version 2 works? Since &...
0
votes
1
answer
2k
views
Node JS / Javascript: Promise, uncaught exception not being handled by 'reject'
I set up the following to handle queries to a SQLite database. When there are no errors with the query, it performs as expected and all rows are logged to the console.
When I test the functionality ...
0
votes
1
answer
73
views
Angular async - how to get the string of an async method
I use this service class in order to get the network status:
@Injectable()
export class NetworkConnectionService {
constructor() {
}
addNetworkConnectionListener() {
Network.addListener('...
1
vote
3
answers
121
views
Loader not remaining visible during execution of a long-running task in JavaScript
I’m trying to show a loading indicator when executing a long-running task. The loader should remain visible for the entire duration of the task and then be hidden when the task completes. However, the ...
2
votes
1
answer
118
views
How can I avoid recursion in this JavaScript function that uses Promises?
I have a JavaScript function that generates an endless slideshow. The code works, but I'm concerned about each iteration ending in a recursive call to itself. Using developer tools, it appears that ...
-1
votes
1
answer
71
views
Promise.race not resolving in useEffect function for React Native mobile app
I am setting up a progressive Image loader (download and replacing an image with the same image in increasing quality). First I am making a cache check to see if the image is already cached. However, ...
0
votes
1
answer
81
views
Promises execution order in Microtask Queue
const p1 = new Promise((_, reject) => {
reject(1);
}).then((r)=>console.log(r)).catch((r)=>console.log(r));
const p2 = new Promise((resolve, _) => {
resolve(10);
}).then((r)=>...
0
votes
1
answer
89
views
Javascript ; loading data from url into object variable before running remaining code
I'm struggling to wrap my head around the javascript async/sync concepts.
I've subclassed an openlayers Layer class for some custom rendering in a map. After instantiating an object of the class, I ...
0
votes
0
answers
78
views
Promise.finally breaking Promise.catch depending on how I assign it [duplicate]
I admit I'm not a JavaScript promises expert, but this is bizarre. I'm creating an API service that's basically an Axios promise factory and importing it into Vue2 components.
The simplified example ...
1
vote
1
answer
138
views
Does Promise.resolve(1); involve microtask queue?
I am searching whether Promise.resolve(1); includes any mcirotask queue or not? There is no .then() or .catch() handler attached to it. Only Promise.resolve(1); Example:
const v = Promise.resolve(1);
...
0
votes
2
answers
92
views
Understanding Promise Chaining Internal Mechanics
I am learning promise chaining and I stumbled upon a doubt. Consider the below promise chain -
const myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("...
0
votes
1
answer
55
views
ECMA proof for statement that in javascript promise handlers(then, catch) are enqueued in microtask queue after promise get resolved or rejected
I was searching the proof of statement that in javascript promise handlers(then, catch) are enqueued in microtask queue after promise get resolved or rejected.
First is above statement true that ...
-1
votes
1
answer
114
views
Can clearTimeout prevent the execution of a callback which has already been moved to the callback queue?
Consider a scenario where I have two tasks -
Task 1 is a callback which is set to be executed after 1 sec using setTimeout.
Task 2 is a synchronous/blocking task which takes comparatively more time ...
2
votes
1
answer
55
views
Empty result using FileReader and promise
I am struggling a bit with asynchronous operations and Promises (a quite new concept to me) using FileReader. I have found a very interesting thread about it there, but can't make my script to work ...
1
vote
1
answer
66
views
Is this an inconsistent behavior with node.js promises?
I've tried to make a Node.js program to connect to a series of TCP sockets using promises.
The primary goal behind this was just a silly test: send a message, and wait for the socket to timeout or ...
2
votes
1
answer
111
views
How do await and Promise.resolve() test whether their arg is a thenable?
I would like to be able to reason about what await will do when it is called on various kinds of values.
The MDN documentation for await describes the decision procedure for that, one of the steps ...
1
vote
2
answers
93
views
Why does `promise.finally` execute after its caller's `then`?
Consider this:
const a = () => {
return new Promise((resolve) => {
resolve(1);
});
};
const b = () => {
return new Promise((resolve) => {
a()
.then((aR) => {
...
1
vote
1
answer
232
views
How to find where promise was created?
I posted this question a couple of days ago, then removed it after I was pointed that it essentially didn't demonstrate the problem I was dealing with. Then I was asked to restore the question, but I ...
1
vote
1
answer
419
views
Is the type of PromiseLike<T> wrong?
Here's code where the type of a promise disagrees with its resolved value:
const p: Promise<number> = Promise.resolve(1);
const q: Promise<string> = p.then<string>();
const r: string ...
1
vote
1
answer
146
views
How does the Promise on requestFullscreen() actually work?
I'm implementing a application in a web browser that has a button to toggle full screen using the Fullscreen Browser API.
I had assumed that I could .then() the promise returned by requestFullscreen() ...
0
votes
0
answers
56
views
Javascript reduce returns empty object in async function
I have an Angular app and I am getting the contents of a json file from Google Drive. The contents is an array of 1011 customers that I want to transform into an object. However the reduce function ...
1
vote
1
answer
62
views
How can I make this variable wait for the fetch inside the weather.getWeather() method
I created a Weather class with methods used to fetch geographical weather info from openweather API.
In my Angular component, I am trying to call the .getWeather(cityName) which gets coordinates for a ...
0
votes
0
answers
35
views
Why is node not awaiting? [duplicate]
With node v18, I am trying to loop over an array of directories, and check if that directory is currently on the main git branch. However the await doesn't seem to be doing anything. I often have ...
1
vote
1
answer
1k
views
How to convert the Playwright Request Object into string as it gives promise only?
I am facing an issue where every time i need to compare response body to some string i need to use response.body().toString() with await which just complicated the code unnecessary is there any other ...
1
vote
1
answer
47
views
Promise.all immediately jumps to then instead of calling all promises
I'm new to promises and trying to get Promises.all to work in this situation. However, when I try to run the code by calling the processFiles function, it just immediately hits the console.log line ...
1
vote
1
answer
173
views
Exiting / cancel rest of the Promise handling
I was reading some posts and got similar question in interview. Lets say the code snippet looks like this:
const newPromise = new Promise((resolve, reject) => reject());
newPromise
.then(() =>...
0
votes
0
answers
50
views
Dealing with leaflet's lack of promises
I'm using the leaflet CDN script in a server-rendered app. The library's methods do not involve promises, so I often get weird UI glitches.
For example, when I use setView() it returns immediately; ...
0
votes
1
answer
457
views
Passing in an Apex method parameter from Promise correctly?
I keep getting an error from the response of my promise, if I give it a parameter. I can't tell if I am suppose to pass in "columndefinitions" parameter to the apex method or not. I have ...
0
votes
3
answers
173
views
Javascript promise chaining not working as expected. After going inside catch block it is still throwing error
I have tried to implement promise chaining in Javascript with 3 simple promises. First promise I am resolving and last 2 I am rejecting. Till 2nd rejection it is working fine. But after the catch ...
0
votes
1
answer
164
views
Promise.race not stopping the execution of long running task [duplicate]
Hi in this code block my requirement is to execute the function test() such that it should stop executing ( it was going through an infinite loop and crashing the page) if it takes for than 1 min.
I ...
1
vote
0
answers
285
views
which executes first, nextTick or promises? [duplicate]
i'm trying to understand the output of a test that i've been running because it seems to go against everything that i'm reading and hearing about how the node.js event loop works. supposedly all ...
-2
votes
2
answers
408
views
Is there a meaningful difference between an async IIFE and a new Promise? [duplicate]
Consider the following assignments:
const promise1 = (async () => {
await someAsyncFunction();
})();
const promise2 = new Promise(async resolve => {
await someAsyncFunction();
...
0
votes
1
answer
374
views
Angular - promise keeps returning ZoneAwarePromise
How would I get the myPromise to be a normal promise instead of a ZoneAwarePromise? I've also unsuccessfully tried wrapping the resolve() in a NgZone.runOutsideAngular() and a setTimeout().
const ...
2
votes
1
answer
65
views
How does nesting of promises work in javascipt [duplicate]
why does it print promise pending?
I was expecting it might give promise<promise<1>> or promise<1>
let k = new Promise((resolve, reject) => {
let a = new Promise((res, rej) =...
0
votes
0
answers
73
views
Promise Fulfilled But Still Pending [duplicate]
I'm writing a function that sends a POST request to my backend API and returns the response as data. I need to use a POST request because I need to send information to the backend. I'm using async/...
0
votes
1
answer
96
views
jQuery .val() does NOT change value for one select element, but does change value for another select
I'm working on a time submission application for contractors that work on special projects. I have two select elements, projectSelect and payPeriodSelect.
I use JavaScript promise chains to retrieve ...
0
votes
1
answer
42
views
On Click of a button make an API call and show the response
I have an array of objects I am intreating that response I want on click of Read More button it will make an API call and display the result of the response and Read More button should not show for ...