22,772 questions
0
votes
2
answers
38
views
why nextjs is sending async prop from a component to a suspended child component
import {Suspense} from "react"
type Props = {
params: Promise<{joblistingId: string }>
}
export default function JoblistingPage(props: Props) {
return (
<...
0
votes
1
answer
105
views
How to terminate an asynchronous function at any point?
I'm looking to cancel an asynchronous function based on a signal that can be controlled by anything, similar to how a fetch can be aborted through the use of an AbortController - effectively ...
0
votes
0
answers
68
views
How does await/async work with TypeScript? [duplicate]
I'm going to put a barebones example here of what I think should work, but doesn't.
const getData = async () => {
const data = await makeAnAsyncCall() //returns a promise of SomeType
...
0
votes
3
answers
116
views
Execution doesn't stop on the first await
Below code (run in: typescriptlang.org):
const sleep = async (ms: number): Promise<void> => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
async function bar(x: number) {...
0
votes
0
answers
50
views
Nuxt Maximum Frequency Data Polling
I'm trying to regularly poll some data in my Nuxt app that will need to be referenced across multiple components. For illustrative purposes, let's say the data is the wind speed, direction, ...
-2
votes
0
answers
75
views
Are these two codes similar
I know these two codes are similar:
This one uses chain of promises:
async function foo(){};
function bar(){};
async function foobar(){};
foo()
.then(bar())
.then(foobar())
And this one uses await:
...
4
votes
2
answers
195
views
Synthetic event becomes stale after async operation
I'm experiencing an issue with a TextField where e.target.value
becomes stale after an async operation(FileReader API) in the onChange handler.
When I capture e.target.value in a variable before the ...
0
votes
0
answers
31
views
An array of promises are all fulfilled by the same asynchronous task with correct return value, but some of them are with undefined value? [duplicate]
I am having an issue with a node.js function that basically works like Array.map() but with the additional capability of limiting how many callbacks are running concurrently (like a mini task ...
2
votes
2
answers
93
views
How to share dependencies in composed Asio operations
This question nerd-sniped me by a problem mentioned in the comments:
@sehe use_promise seems very interesting. I looked up some
documentation about it and found some of your posts, like this. But
how ...
0
votes
0
answers
91
views
Searching for an elegant way instead of using recalling setTimeout for Promises
I'm written an Promise class to block while async transfers json are done.
For every async transfer I call before "addwaiter", when the transfer is done I call "removewaiter".
The ...
1
vote
3
answers
83
views
How should I write a javascript promise to wait for a response from socket stream?
I have an object that communicates two-way with another program ('remote') using TCP socket. The incoming messages (from remote) may arrive unsolicited as well as a response to a message sent to the ...
-1
votes
2
answers
72
views
browser sequentially sending data to server with sleep
having large amount of browser data - json sent to the server side, so wanna to chunk the data and send to the server sequentially with sleep 1 seconds between each sending.
have tried two ways:
way 1:...
1
vote
1
answer
63
views
Why does my async function return a pending Promise instead of the expected value in JavaScript? [duplicate]
I’m trying to call an async function and get the result, but instead of the actual data, I get a pending Promise. Here’s a simplified version of my code:
async function getData() {
const response = ...
0
votes
2
answers
111
views
How to wait for Worker-Threads execution with Promises
I have a Node.js script where I need to parse a bunch of big files. My first attempt was using Promises, in general it is working. However, the script is as slow as reading the files one-by-on in a ...
1
vote
1
answer
107
views
How to return both early result and final async result using Promise?
When I make a POST request, the server responds immediately with an id, but the actual result is delivered later via a server push event (e.g., WebSocket or Pusher).
Here's what I'm trying to do:
When ...
0
votes
1
answer
85
views
Can a promise resolve statement await a return from the function awaiting the promise?
In this example code, the showMenu button requests a sort of custom context menu which returns a promise waiting for the user to make a selection from the menu. When the menu is requested, a busyType ...
0
votes
1
answer
102
views
Getting error while deployment of next js app but it runs locally without error [closed]
I'm deploying a Next.js 15.3.3 app to Vercel and encountering a TypeScript error related to dynamic route parameters. The error says:
"Type '{ params: { questionId: string; questionSlug: string; }...
2
votes
2
answers
66
views
Array of images each with an onload event listener
I have an array of image objects that I set an event listener for. Inside the event listener, I just increment the value of a progress bar (the full bar when all images finish loading.
let images =...
0
votes
1
answer
77
views
Can an inappropriate callback be passed to waitFor?
I was going over Road to React (the book by Robin Wieruch), and I encountered a confusing piece of code. The code is on the Testing chapter, page 227:
describe('App', () => {
it('succeeds ...
0
votes
1
answer
71
views
Do you need await for writes and transactions in Firebase Realtime Database?
Why does Firebase Realtime Database's transaction work without the await keyword as the updated official doc example shows (a few years ago, they all required await)? These write methods still return ...
-3
votes
1
answer
100
views
JavaScript return last then as a promise [duplicate]
I wrote the following code to resize an image:
Main().then(function(x) {
console.log(x)
});
Main=function() {
Base64()
.then(function(i) {
ImageObject(i)
})
.then(function(i) {
...
-1
votes
1
answer
48
views
How to set result on a Promise outside of its constructor callback?
How do you resolve/reject a Promise outside of the constructor callback? My goal is to return a Promise that will later be resolved/rejected in the middle of a promise chain. E.g.,
function ...
0
votes
0
answers
101
views
How can I prevent an app from crashing on unhandled promise rejections?
I'm working on a Vue 3 application using TypeScript and Axios. I already have an axios interceptor that handles errors and shows alerts/modals using a custom system. However, if I make a request in a ...
-2
votes
1
answer
80
views
How to modify data before resolving a promise in Javascript [closed]
I have a database with text entries.
I want to search for the city name, and return the country.
I have an async function which returns a thenable promise.
getText('New').then(alert(result));
After ...
0
votes
1
answer
75
views
calling each element inside Promise.all with await
const results = await Promise.all([
await asyncTask1(), await asyncTask2(), await asyncTask3()
]);
Will the code snippet above produce a bug, or will it defeat the purpose of Promise.all as each ...
0
votes
1
answer
50
views
3rd party js (Malle) does not find elements generated by javascript in a promise (vanilla js) [closed]
I have a simple web page with some divs with data in them, and I would like to make some of the text editable by using Malle.js. This is super simple in theory, and it works perfectly for any text ...
-1
votes
2
answers
90
views
Waiting for all side promises to finish before "then()" execution
In section then3 I want to generate promises with further operations on their content inside 2 "thens". In case they were fetches, I want to limit their start to for example 3 at once every ...
0
votes
1
answer
110
views
v8 Promise 'then' is called only if resolved in constructor
I have following problem with C++/v8 interoperability. When I resolve the promise outside the constructor, the then callback never gets called. Here is the javascript v8 code:
'use strict';
v8log (&...
0
votes
0
answers
67
views
How to control the order of promise's callback [duplicate]
I have promises like this,
var results_arr = [];
var promises = [];
for (var i = 0 ; i < items.length;i++){
var url = `/api/stat/${items[i].id}`;
promises.push(
...
0
votes
1
answer
51
views
How to pass variables other than the Promises between multiple .then() chains?
After looking up answers about how to download files with Axios in React I implemented the following code:
const [fileName, setFileName] = useState("")
const [extension, setExtension] = ...
1
vote
2
answers
112
views
Can I capture an external async function unhandled error?
Let's suppose I want to use an async function foo from an external library, which calls another async function bar that throws an error that foo does not handle:
// External library code (non-...
2
votes
1
answer
119
views
Why does "finally" delays the execution of "then" attached to it?
In this example:
const foo = async () => {
const a = await (Promise.resolve(1).then(v => console.log(v)));
console.log('foo');
return 1;
}
const value = foo();
value
.then(a => ...
1
vote
1
answer
45
views
Continue running upon result from modal dialog
The following code is for modal dialog component.
I want it to act like "confirm".
Running will proceed only after clicking 'yes' (return true) or 'no' (return false) in the dialog.
import { ...
1
vote
1
answer
128
views
What is the order of microtasks in multiple Promise chains?
Out of an academic interest I am trying to understand the order of microtasks in case of multiple Promise chains.
I. Two Promise chains
These execute in a predictable "zipped" way:
Promise....
1
vote
1
answer
37
views
axios interceptor rejected promise doesn't trigger useMutation() isError parameter to turn to true
I am trying to use an axios interceptor return response.data or a rejected promise on error on every call to api.
I have confirmed the backend recieves the data and I can create a new user if all the ...
0
votes
0
answers
34
views
Can I Wrap `ts-morph` Functions in Promises for TypeScript Compatibility in Node.js?
I'm using ts-morph in a Node.js environment, but its synchronous functions are blocking the main thread, which causes issues with a terminal spinner (since the spinner also runs on the main thread in ...
0
votes
0
answers
73
views
Streaming promises crashes the entire app with ERR_UNHANDLED_REJECTION when backend is not reachable.How to handle errors on streaming promises?
Setup
I have an express backend server running on localhost:8000
My sveltekit frontend is running on localhost:5173
Problem
I shut my backend server down to see what happens on the frontend
I ...
1
vote
1
answer
332
views
Angular provideAppInitializer is initialized after ngOnInit
I have in my ApplicationConfig provider
provideAppInitializer(() => {
inject(AppConfigService)
})
In component MainPageComponent I have ngOnInit(), which geting data from backend every refresh.
...
0
votes
1
answer
70
views
How to return promise in partially async function [closed]
I have a function that goes like this:
async function(field1, field2) : Promise<boolean> {
if(aCondition) {
await nestedFunc().then(doSomethingwithDataFromAwait()
return true;
...
-1
votes
1
answer
51
views
Can I avoid awaiting an async function if no return is expected or required [duplicate]
I think I understand async/await but I am confused by a part I have reached in my code in a very common scenario.
I have an async function createOrder() that processes orders. Before that function ...
-1
votes
1
answer
97
views
How to locate where UnhandledPromiseRejection is coming from? Already tried a few things
I'm currently building a node.js server application and getting this error message in the server console:
$ tsc && webpack && DEBUG=express:* node --trace-warnings --unhandled-...
0
votes
1
answer
717
views
PixiJS 8 Assets Loading
I'm trying to follow this example in order to figure out how to write a project which uses a PixiJS, TypeScript/JavaScript, and Webpack. The problem I'm facing with the index.ts file code which I ...
1
vote
0
answers
139
views
Using React's suspense causes infinite loop of a re-render
Here's a snippet of my code
// Cache the data fetching function
const getCached = cache(async (id: string) => {
return await getData(id, ['general']);
});
// Data fetching component
function ...
0
votes
1
answer
295
views
'promise_type' is not a member of std::coroutine_traits
i have a class template called "guard_if" that is supposed to enable guards against function execution if specific criteria are not met. This class template takes two main parameters, a std::...
0
votes
1
answer
91
views
When does Promise resolve/reject actually add a micro task?
When does Promise resolve/reject actually add a micro task?
I read the Promise/A+ implementation code from here, and understood that task adding action is triggered after resolve() (the mentioned ...
2
votes
1
answer
122
views
Are promise handlers cleared from memory after the promise is resolved?
I have an Angular app. I have a service, which has an initialization logic - a backend call to fetch some data. Once the backend call is processed, I resolve a promise, indicating the service is ready ...
0
votes
0
answers
42
views
trello authenticate user for token
async authenticateTrello() {
const authUrl = `https://trello.com/1/authorize?expiration=1hour&name=TrelloPlanner&scope=read,write&response_type=token&key=${TRELLO_APP_KEY}`;
...
0
votes
1
answer
183
views
Getting typescript error Type error: Type '() => Promise<{ message: string; } | undefined>' is not assignable to type 'string | ((formData: FormData)
/component/button.tsx
"client component"
export const DeleteButton = ({ id }: { id: string }) => {
const deleteImageWithId = deleteImage.bind(null, id);
return (
<form
...
3
votes
2
answers
180
views
What is the cause of this async bug and why is it fixed with a blocked scoped const variable
I've been reading through the Asynchronous Programming chapter of Eloquent JavaScript and came across this async bug problem. The solution offered here was to do a .join() at the end, but I came ...
0
votes
0
answers
37
views
infer type of Higher order function return value when function parameter returns a promise
Basically I am trying to create a function defined like this:
function result<T>(cb: () => T): Result<T,Error> {
try {
return Ok(fn());
} catch (error) {
return Err(
...