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

How to rewrite a function under async/await?

I want to stop using the async library, replacing it with vanilla js. const async = require('async') function getTopicsData(tids, Uid, callback) { async.map(tids, (tid, next) => { redis.hgetall(`topic:${tid}`, (err, topics) => { …
NCHAryON
  • 61
  • 1
  • 6
3
votes
1 answer

Imported async functions don't properly resolve data

Background: I have been using create-react-app to create React components and my latest project requires a server backend to return data. I like to mock up the data returned by the API with imported functions from a 'API' file. Recently, I have…
3
votes
2 answers

Async throwing SyntaxError: Unexpected token (

I'm running a test using the headless Chrome package Puppeteer: const puppeteer = require('puppeteer') ;(async() => { const browser = await puppeteer.launch() const page = await browser.newPage() await page.goto('https://google.com',…
alex
  • 7,111
  • 15
  • 50
  • 77
3
votes
1 answer

How to use generator.next() inside while loop?

I have generator function* pendingPage() { let value = 1; while (true) yield getPage(value++); } I have getPage() function async function getPage(value) { const page = await service.getValidations(value); …
Remzes
  • 269
  • 1
  • 3
  • 17
3
votes
0 answers

How could I throw error in nested function for async syntax?

I need to do something like this: const fn = () => new Promise((resolve, reject) => { const timeout = setTimeout(() => reject('time out!'), 3000); doSth().then((d) => { clearTimeout(timeout ); resolve(d); …
3
votes
1 answer

Using babel-polyfill in production entry file

I'm using babel to transpile ES7 js code, and everything works like a charm in dev/staging. Inside the application, I heavily rely on async/await features of ES7. My entry file looks like this: 'use…
Ivan
  • 769
  • 5
  • 17
3
votes
1 answer

Is it possible to wrap function such as Geolocation.watchPosition() in a Promise?

I wonder if it's possible to wrap Geolocation.watchPosition() https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition in a Promise and use it with async/await idioms in a way it does it's work; constantly returns positions…
tkymtk
  • 2,695
  • 3
  • 21
  • 37
3
votes
1 answer

Why does ES2017 introduce async/await when ES6 already has generators?

When reading about async and await, I noticed that it's almost an equivalent of generator functions. Consider this fragment from TypeScript Deep Dive: Async Await (...) // Not actual code. A thought experiment async function foo() { try { …
mik01aj
  • 11,928
  • 15
  • 76
  • 119
3
votes
2 answers

Trying to use async/await in mocha

I want to use async/await in mocha in order to make my tests. I have read many post, but I didn't find the solution. I have already install all the babel modules in order to transpiling the code, but it doesn't work. Here is my code inside the…
maoooricio
  • 2,249
  • 3
  • 15
  • 19
3
votes
1 answer

async await on Jquery ajax callback?

I'm trying to do this with async/await, but any solution is good. Anyone know how I could change this: series[group].forEach(async (ele, j) => { await $.ajax({ url: `templates/ele${ele}.template.html`, success: function (data) { …
roberto tomás
  • 4,435
  • 5
  • 42
  • 71
3
votes
1 answer

JavaScript await by default instead of manually

Async/await are really handy, but I want the opposite of their behavior. Instead of other functions continuing on unless I manually ask them to await a promise, I want functions to yield unless I manually specify that they continue running in…
3
votes
2 answers

Promise to async/await

I'm having following code. class DB { constructor(client) { this.client = client; } } export default function store() { return new Promise((resolve, reject) => { pg.connect(process.env.DATABASE_URL, client => { …
Artem Gurzhii
  • 49
  • 2
  • 5
3
votes
1 answer

javascript async/await in a generic loop

I want to make this example https://stackoverflow.com/a/33585993/1973680 synchronous. Is this the correct implementation? let times= async (n,f)=>{while(n-->0) await f();} times(5,()=> myfunc([1,2,3],err => err) …
leonard vertighel
  • 1,058
  • 1
  • 18
  • 37
3
votes
1 answer

Calling an async function with default parameter as function for arguments checking handled synchonous?

I am using async functions and default parameters with evaluation at call time. With the default parameters I use a function to check if a value is provided or not. function mandatory(paramName) { throw new Error(`Missing parameter:…
rolfst
  • 31
  • 3
3
votes
1 answer

eslint await Expected an assignment or function call and instead saw an expression

When I place this code for a promise that the result is not needed to proceed: await resultNotNeeded(bla, foo); I'm getting this eslint error: [eslint] Expected an assignment or function call and instead saw an expression.…
David
  • 2,741
  • 16
  • 26