All Questions

3621
votes
25answers
942166 views

How do I return the response from an asynchronous call?

I have a function foo which makes an Ajax request. How can I return the response from foo? I tried to return the value from the success callback as well as assigning the response to a local variable ...
195
votes
5answers
63005 views

Using async/await with a forEach loop

Are there any issues with using async/await in a forEach loop? I'm trying to loop through an array of files and await on the contents of each file. import fs from 'fs-promise' async function printF...
26
votes
1answers
20016 views

try/catch blocks with async/await

I'm digging into the node 7 async/await feature and keep stumbling across code like this async function main() { try { var quote = await getQuote(); console.log(quote); } catch(error) { ...
4
votes
1answers
3212 views

Correct Try...Catch Syntax Using Async/Await

I like the flatness of the new Async/Await feature available in Typescript, etc. However, I'm not sure I like the fact that I have to declare the variable I'm awaiting on the outside of a try...catch ...
28
votes
4answers
5788 views

ES2017 - Async vs. Yield

I am confused about the current discussion of adding async functions and the keyword await to the next EcmaScript. I do not understand why it is necessary to have the async keyword before the functio...
13
votes
2answers
4536 views

Is using async in setTimeout valid?

I had a asynchronous function in Javascript and I added setTimeout to it. The code looks like that: let timer; clearTimeout(timer); timer =setTimeout(() => { (async...
35
votes
4answers
15904 views

Use async await with Array.map

Given the following code: var arr = [1,2,3,4,5]; var results: number[] = await arr.map(async (item): Promise<number> => { await callAsynchronousOperation(item); return item ...
8
votes
3answers
2921 views

Is async await truly non-blocking in the browser?

I have been playing around with the feature in an SPA using TypeScript and native Promises, and I notice that even if I refactor a long-running function into an async function returning a promise, the...
36
votes
3answers
14917 views

How to reject in async/await syntax?

How can I reject a promise that returned by an async/await function? e.g. Originally foo(id: string): Promise<A> { return new Promise((resolve, reject) => { someAsyncPromise().then((v...
7
votes
1answers
1578 views

Is there a way to wrap an await/async try/catch block to every function?

So i'm using express.js and looking into using async/await with node 7. Is there a way that I can still catch errors but get rid of the try/catch block? Perhaps a function wrapper? I'm not sure how th...

Previous Next