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
34
votes
4 answers

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 function keyword. From my point of view the await keyword…
Danny
  • 1,078
  • 7
  • 22
27
votes
5 answers

Is it possible to use await without async in Js

Await is a amazing feature in es7. However,everytime I use await I found that I have to define a async function and call this function. Such as async function asy(){ const [resCityGuess,resCityHot,resCityAll]=await Promise.all([ …
曾志强
  • 281
  • 1
  • 3
  • 6
23
votes
2 answers

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() => { await this._doSomething(); …
Marta
  • 2,857
  • 13
  • 46
  • 67
22
votes
2 answers

async/await native implementations

This proposal suggests that async functions can use generator functions under the hood, although I cannot find a confirmation of this in ES2017 spec. Moreover, when generator prototype becomes messed up in Chrome/Node.js, async functions don't seem…
Estus Flask
  • 206,104
  • 70
  • 425
  • 565
21
votes
3 answers

Is it possible to resolve async function without return keyword

I started to use ES7 feature async/await , which gives the best approach to deal with asynchronous tasks, and makes your code cleaner and readable. However it doesn't give you an access to Promise, created by async function, so if you do some async…
rokstar
  • 404
  • 1
  • 3
  • 12
19
votes
1 answer

async/await and recursion

I'm trying to code a method that show recursively an ActionSheetIOS to select a value contained from arrays and return the selected values: async function _rescursiveSelect(data, index) { if (index < data.length) { const object =…
Jean Lebrument
  • 5,079
  • 8
  • 33
  • 67
18
votes
5 answers

How do I wrap a callback with async await?

My function returns a promise that resolves as soon as the HTTP server starts. This is my code: function start() { return new Promise((resolve, reject) { this.server = Http.createServer(app); this.server.listen(port, () => { …
Tiago Bértolo
  • 3,874
  • 3
  • 35
  • 53
18
votes
3 answers

react-native async function returns promise but not my json data?

I'm learning react-native, and I'm running into an issue. Why does getting data on return from an async function return a promise, but in the async function itself, it correctly returns an array of objects? On componentDidMount(), I call my async…
tempomax
  • 773
  • 4
  • 10
  • 24
18
votes
1 answer

Unexpected identifier when using await

I'm currently trying to use async/await for a function that requires the loop to be synchronous. This is the function: async channelList(resolve, reject) { let query = ['channellist'].join(' '); this.query.exec(query) .then(response =>…
18
votes
6 answers

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 this would actually execute the function's code and…
Neverlax
  • 405
  • 2
  • 5
  • 15
17
votes
1 answer

Using await in then callback - the keyword 'await' is reserved

In node.js, I have a database transaction, where I want to call an async method in then callback, but I get error message the keyword 'await' is reserved. This is async saveImage function: const saveImage = async (parsedLink) => { …
Matt
  • 8,195
  • 31
  • 115
  • 225
17
votes
2 answers

Returning an awaited value returns a Promise? (es7 async/await)

const ret = () => new Promise(resolve => setTimeout( () => resolve('somestring'), 1000)); async function wrapper() { let someString = await ret(); return someString; } console.log( wrapper() ); It logs Promise { }; Why does it…
bool3max
  • 2,748
  • 5
  • 28
  • 57
16
votes
5 answers

What's the actual use of the Atomics object in ECMAScript?

The ECMAScript specification defines the Atomics object in the section 24.4. Among all the global objects this is the more obscure for me since I didn't know about its existence until I didn't read its specification, and also Google hasn't many…
16
votes
2 answers

Async / await assignment to object keys: is it concurrent?

I know that doing this: const resultA = await a() const resultB = await b() // code here Is effectively a().then( resultA => { b().then( resultB => { // code here }) }) Basically, a() runs then b() runs. I nested them to show that both…
Babakness
  • 2,954
  • 3
  • 17
  • 28
15
votes
1 answer

How do I target ES2018 in TypeScript?

I am targeting ES2018 and do not care about ES3 or ES5. From my tsconfig.json: "target": "ES2018". tsc complains: An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise'…
mikemaccana
  • 110,530
  • 99
  • 389
  • 494
1 2
3
25 26