javascript - Unexpected identifier when using await -


i'm trying use async/await function requires loop synchronous.

this function:

async channellist(resolve, reject) {     let query = ['channellist'].join(' ');      this.query.exec(query)     .then(response => {         let channelsraw = response[0].split('|');         let channels = [];          channelsraw.foreach(data => {             let dataparsed = responseparser.parseline(data);              let method = new channelinfomethod(this.query);             let channel = await method.run(dataparsed.cid);              channels.push(channel);         });          resolve(channels);     })     .catch(error => reject(error)); } 

when try run it, error:

let channel = await method.run(dataparsed.cid);                     ^^^^^^ syntaxerror: unexpected identifier 

what cause of it?
thanks!

your async defined on channellist , not on arrow function await contained. move async arrow function:

channelsraw.foreach(async (data) => {     let dataparsed = responseparser.parseline(data);      let method = new channelinfomethod(this.query);     let channel = await method.run(dataparsed.cid);      channels.push(channel); }); 

also, since you're using async anyways, can async entire promise chain have there.


Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -