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.
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…
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…
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…
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):…
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…
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…
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…
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)…
My case:
let waiting = function () {
return new Promise(resolve => {
console.log('awaiting...');
setTimeout(function () {
resolve();
}, 1000)
});
};
let waitingAsync = async function () {
…
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…
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 () {
…
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…
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);
…