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
4
votes
1 answer

Class constructor's caller function

Is there a way to get the caller function of the class's constructor? class TestClass { constructor(options) { if( !== TestClass.create) throw new Error('Use TestClass.create() instead') this.options = options } static…
4
votes
2 answers

ES7 - how can I replace Promise with await?

One thing puts me off with Promise is that it is difficult to grasp with resolve and reject. Also the need of wrapping for Promise is ugly. Unless you use it very often, I tend to forget how to use them over time. Besides, code with Promise is still…
Run
  • 54,938
  • 169
  • 450
  • 748
4
votes
1 answer

"SyntaxError: Unexpected token )" in Node.js

I keep getting a SyntaxError: Unexpected token )' error for the following code: passport.use( 'local-signup', new LocalStrategy({ usernameField: 'email', passwordField: 'password', passReqToCallback: true, // pass back req to…
4
votes
2 answers

async/await clarity, with sleep example

I am trying to get hang of async/await with below implementation but it is not working as expected public static async sleep(ms: number): Promise { await Utilities._sleep(ms); } private static _sleep(ms: number):…
harishr
  • 17,807
  • 9
  • 78
  • 125
4
votes
1 answer

How can I define an async function in an object literal

Whenever I try to define an async function inside an object this way it throws a Syntax error. let obj = { fn: async function fn() { return 10; } }
4
votes
1 answer

How to use await on fixture.whenStable in Angular 2 Tests

Though whenStable returns a promise, I'm not allowed to use await. Below are my tsconfig "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "target": "es5", "typeRoots": [ "node_modules/@types" ], I'm…
Prashan Fernando
  • 281
  • 4
  • 11
4
votes
2 answers

How to reduce use of await keyword in async await while maintaining execution order

async function foo() { await this.getAsync(); await this.getAsyncTwo(); await this.getAsyncThree(); await this.getAsyncFour(); } See how foo has multiple await calls, is there a way of simplyfing this while keeping execution order? I wish…
Cisum Inas
  • 11,552
  • 11
  • 40
  • 55
4
votes
2 answers

Javascript minifier supporting ES2017 async/await feature

Currently appears as UglifyJS2 and Google Closure doesn't support JavaScript minification of scripts including async/await usage without transpiling them. Is there a way or another minifier to get these JavaScript scripts minified without the need…
Eghes
  • 95
  • 10
4
votes
1 answer

How does async/await work with callbacks in the async function?

async setMyPhotos() { const newPhotos = await Promise.all(newPhotoPromises); someOtherPromise(); // will wait for newPhotoPromises syncAvatar(newPhotos[0], function(res, err) { // does this wait for newPhotoPromises too? if (!err)…
atkayla
  • 8,143
  • 17
  • 72
  • 132
4
votes
5 answers

How to await an asynchronous function?

My case: let waiting = function () { return new Promise(resolve => { console.log('awaiting...'); setTimeout(function () { resolve(); }, 1000) }); }; let waitingAsync = async function () { …
Tân
  • 1
  • 15
  • 56
  • 102
4
votes
3 answers

Angular 1.5 && Async/Await && jasmine tests

I already looked everywhere but could not find a solution yet for my particular case. We are using angular 1.5 and a Karma/Jasmine setup for unit tests. In the initial source code, I used ES2017 async/await in the controller. That seemed to work…
dejakob
  • 2,062
  • 14
  • 21
4
votes
2 answers

Chaining async functions?

let val = 0; async function first() { console.log('1a', val); second(); console.log('1b', val); } async function second() { console.log('2a', val); third(); console.log('2b', val); } async function third() { …
basickarl
  • 37,187
  • 64
  • 214
  • 335
4
votes
1 answer

Difference between co and await

I'm not really understanding the difference between this code: co(function *() { const val = yield aPromise(); return val; }) .then((val) => doSomethingWith(val), (err) => doSomethingWith(err)); and this other one: async function () { …
David
  • 2,741
  • 16
  • 26
4
votes
1 answer

Async / Await JS Catch not working in try/catch

I have the bit of javascript below. Using async/await in our ES6 project. I have noticed that now all of a sudden a 404 response code isn't hitting the catch. In fact the .json() is also throwing a console error but still not hitting the catch. I…
allencoded
  • 7,015
  • 17
  • 72
  • 126
4
votes
1 answer

async/await mocking

I was wonder if one can do something like this with async/await in tests. With regular promises I can for example mock out a promise in unit test like this. class Foo { fn() { this.someService.someFn().then((data) => this.data = data); …
Kapaacius
  • 655
  • 4
  • 10
  • 22