Questions tagged [ecmascript-2017]

Use this tag for questions about features finalized in ECMAScript 2017. Do *not* use this tag if the code in question merely *uses* one of the features, *unless* the feature is cause of the problem.

Proposals finalized in 2017 include:

387 questions
73
votes
5 answers

async/await always returns promise

I'm trying async/await functionality. I have such code imitating a request: const getJSON = async () => { const request = () => new Promise((resolve, reject) => ( setTimeout(() => resolve({ foo: 'bar'}), 2000) )); const json = await…
user3309314
  • 2,453
  • 2
  • 17
  • 30
71
votes
3 answers

Use Async/Await with Axios in React.js

Following How to use async/await with axios in react I am trying to make a simple get request to my server using Async/Await in a React.js App. The server loads a simple JSON at /data which looks like this JSON { id: 1, name: "Aditya" } I…
Singh
  • 1,887
  • 3
  • 18
  • 29
69
votes
5 answers

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 UI is still unresponsive. So my questions…
prmph
  • 7,616
  • 11
  • 37
  • 46
66
votes
2 answers

ES7, ES8, ES9, ES10, ES11 Browser support

Regarding compatibility between ECMAScript specification and actual implementation; It is fairly easy to check out the data about browser support for ECMAScript2015 (ES6), but I found it pretty difficult to have an equivalently clear table for all…
Alvin Sartor
  • 2,249
  • 4
  • 20
  • 36
60
votes
1 answer

Is it safe to use async/await now?

Is it safe to use async-await in Javascript instead of generators-promises now, knowing that the syntax has not made yet and will be coming with the release of ES8? What browsers can I count on it being available, and how common are the browsers…
Abhijeet Ahuja
  • 5,596
  • 5
  • 42
  • 50
58
votes
2 answers

ES8 Immediately invoked async function expression

I haven't seen these constructs used much but I've found myself writing them to make use of async / await in functions that wouldn't typically return a promise, for example chan.consume(queue, (msg) => { this.pendingMsgs++; // executed…
Drew R
  • 2,988
  • 3
  • 19
  • 27
53
votes
4 answers

Waiting for more than one concurrent await operation

How can I change the following code so that both async operations are triggered and given an opportunity to run concurrently? const value1 = await getValue1Async(); const value2 = await getValue2Async(); // use both values Do I need to do something…
Ben Aston
  • 53,718
  • 65
  • 205
  • 331
52
votes
1 answer

Why are await and async valid variable names?

I was experimenting with how / is interpreted when around different keywords and operators, and found that the following syntax is perfectly legal: // awaiting something that isn't a Promise is fine, it's just strange to do: const foo = await…
46
votes
1 answer

Why doesn't the code after await run right away? Isn't it supposed to be non-blocking?

I have a hard time understanding how async and await works behind the scenes. I know we have promises which make our non blocking code by using the "then" function we can place all the work we need to do after the promise is resolved. and the work…
Rohail Najam
  • 1,031
  • 1
  • 8
  • 11
45
votes
3 answers

Node repl with async await

I would like to add support to async/await to node repl Following this issue: https://github.com/nodejs/node/issues/8382 I've tried to use this one https://github.com/paulserraino/babel-repl but it is missing async await suppport I would like to use…
42
votes
4 answers

How to use async/await in Vue.js?

I'm new in ES7 I want to use async/await in Vue.js Here is my code created (){ this.getA() console.log(2) this.getB() }, methods : { getA (){ console.log(1) }, getB (){ console.log(3) } } It returns…
USER
  • 741
  • 4
  • 10
  • 21
41
votes
1 answer

running queries in firebase using async / await

Appreciating that firebase has added support for promises, is there a way to run a query like the following inside of an async function?: const eventref = this.db.ref('cats/whiskers'); const value = await eventref.once('value') Running the above…
fox
  • 15,428
  • 20
  • 55
  • 85
37
votes
1 answer

How to use Promise.prototype.finally() in async/await syntax?

Actually my main question was using Promise.prototype.catch() in async/await ES8 syntax, Undoubtedly Promise.prototype.then() is existed in essence of async/await syntax. I searched about using Promise.prototype.catch() in async/await and found…
AmerllicA
  • 29,059
  • 15
  • 130
  • 154
36
votes
5 answers

Chain async functions

In an async function, I can get an asynchronous value like so: const foo = await myAsyncFunction() If I want to call a method on the result, with a sync function I'd do something like myAsyncFunction().somethingElse() Is it possible to chain calls…
Asherlc
  • 1,111
  • 2
  • 12
  • 28
34
votes
4 answers

When to mark function as async

Basically, function must be prefixed with async keyword if await used inside it. But if some function just returns Promise and doesn't awaiting for anything, should I mark the function as async? Seems like both correct or not? // with async (returns…
Maksim Nesterenko
  • 5,661
  • 11
  • 57
  • 91
1
2
3
25 26