7
我目前正在嘗試使用async/await函數,要求循環是同步的。使用await時意外的標識符
這是函數:
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));
}
當我嘗試運行它,我得到這個錯誤:
let channel = await method.run(dataParsed.cid);
^^^^^^
SyntaxError: Unexpected identifier
什麼可能是它的原因是什麼?
謝謝!
我現在覺得很傻,沒有意識到它是在回調。謝謝 :) –