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
6
votes
2 answers

How to achieve parallelism for SharedArrayBuffer and Atomics?

ECMA-2017(ES8), just finalized about a month ago, introduces SharedArrayBuffer and Atomics. The link here shows that they have been supported in some browsers. As we know, they are meant to allow the sharing of data across threads. I wonder how this…
6
votes
2 answers

Capturing Responses other than 200 OK From Fetch

I'm using the native fetch library as specified here. It seems that whenever a response other than a 200 OK is returned it throws an exception with the string response Uncaught (in promise) TypeError: Failed to fetch. Was there a way to catch and…
James Marino
  • 668
  • 1
  • 9
  • 25
6
votes
1 answer

How to use "await" for a generator function is ES6?

The issue I'm curious if it would be possible to consume a generator-function in async/await context within modern ES2017. (The application is a React-native-application) This is my code where I want to call the generator function: class…
delete
  • 18,144
  • 15
  • 48
  • 79
6
votes
1 answer

Can I use async/await to wait for multiple events in JavaScript?

Consider the following case: const waitForEvent = async (api) => { api.on('eventOne', () => { return 'eventOne'; }) api.on('eventTwo', () => { return 'eventTwo'; }) api.on('eventThree', () => { return 'eventThree'; }) …
aaa
  • 601
  • 6
  • 13
5
votes
1 answer

What is the difference between the specification types Environment Record (Lexical Environment) and Reference, in ECMAScript?

Reading the ECMAScript specification, it seems both an Environment Record (a component of a Lexical Environment), and a Reference is used to determine what variable / function an Identifier is bound to. In other words, finding the actual value…
Magnus
  • 6,791
  • 8
  • 53
  • 84
5
votes
1 answer

ES7 - How to stop(cut) async/await chaining

If I use async/await function in a nested function call, I think the callers of that async/await functions should have async/await prefix. For example, in this situation: function a() { b(); } function b() { c(); } function c() { …
yakkisyou
  • 510
  • 7
  • 14
5
votes
2 answers

How to test a method that uses async/await?

I've seen a lot of articles about how use async/await in your unit tests, but my need is the opposite. How do you write a test for a method that uses async/await? My spec is not able to reach any code after the 'await' line. Specifically, the spec…
user2954463
  • 2,362
  • 2
  • 23
  • 37
5
votes
1 answer

When is `await` resolved simultaneously?

The MDN documentation for async function currently gives the following combined example of two ways to use await. I've reordered it just a bit for emphasis: function resolveAfter2Seconds(x) { return new Promise(resolve => { setTimeout(() => { …
natevw
  • 16,807
  • 8
  • 66
  • 90
5
votes
1 answer

Re-throwing exception on catch to upper level on async function

Throwing error to upper level in an async function This async create(body: NewDevice, firstTry = true): Promise { try { return await this.dataAccess.getAccessToken() } catch (error) { throw error } } VS…
Iván E. Sánchez
  • 1,183
  • 15
  • 28
5
votes
2 answers

Testing angular service with $httpBackend with async/await using jasmin

I have previously successfully tested an angular controller that uses ES7 async/await syntax with jasmine - async updateGridAsync() { const paging = angular.copy(this.gridData.getServerCallObj()); } try { …
Rotem B
  • 1,327
  • 1
  • 15
  • 20
5
votes
1 answer

In es2017, 'this' is undefined when accessed from async methods

How to refer to class instance when called from an async method. class Senders { callSendAPI() { //Some code here } sendText() { this.callSendAPI(); } async sendCards() { var dbpromise = await db.call(); console.log('this=…
ishandutta2007
  • 16,676
  • 16
  • 93
  • 129
5
votes
2 answers

Object.entries() and Object.values() are not typed as arrays in WebStorm/PhpStorm

I have TypeScript project with ES6 target, it uses core-js to polyfill ES2017 features and tsconfig.json is configured accordingly. When Object.entries(...) and Object.values(...) are used, the results don't have array methods and properties (map,…
Estus Flask
  • 206,104
  • 70
  • 425
  • 565
5
votes
1 answer

Control Which Code Stops with Async/Await

Can you stop code outside of the async function using await? However, I don't want all code to stop. I want to control what code will run. I think there might be a solution, something like this: var isAsyncRunning = false; var currentPromise; async…
5
votes
4 answers

How To Synchronise Promise Objects?

I have promise objects which need to work synchronize. For example second promise shouldn't work before first one is done. If first one rejects first one has to be executed again. I have implemented some examples.This one works well. call getVal,…
Burak Karasoy
  • 1,682
  • 2
  • 21
  • 33
4
votes
3 answers

Why can't class methods call other class methods or themselves?

I am curious why methods cannot call other methods or themselves in javascript. For example, this produces a Reference error saying add is not defined. class sum { add(x, amt) { if(amt == 0) return x return add(x+1, amt-1) } } summer =…
Thomas
  • 6,032
  • 6
  • 41
  • 79