All Questions

3425
votes
23answers
902562 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 ...
150
votes
5answers
45045 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...
19
votes
1answers
14960 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) { ...
23
votes
4answers
5390 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...
11
votes
2answers
3267 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...
22
votes
3answers
8930 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
1363 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...
13
votes
2answers
6774 views

(ES6) class (ES2017) async / await getter

Is it or will it be possible to have an ES6 class getter return a value from an ES2017 await / async function. class Foo { async get bar() { var result = await someAsyncOperation(); ...
8
votes
3answers
1833 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...
4
votes
1answers
1105 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 ...

Previous Next