简体   繁体   中英

SyntaxError: unexpected reserved word 'await' in async function

Here is my code. Can't figure out why the error occured. The function is async type.

 const func = async () => { {submission[0].emoticons.map((item, idx) => { console.log('apngToFrame is working') const imgsrc = `${url}${item.id}` var container2 = document.querySelector('.output2') const response = await fetch(imgsrc) const buffer = await response.arrayBuffer() const apng = parseAPNG(buffer) if (apng instanceof Error){ console.error('apng.message', apng.message) return ; } await apng.createImages() apng.frames.forEach(f => { container2.appendChild(f.imageElement) }) })} }

Add async for the callback function that you are using in the map

const func = async () => {
      {submission[0].emoticons.map(async(item, idx) => {
        console.log('apngToFrame is working')
        const imgsrc = `${url}${item.id}`
        var container2 = document.querySelector('.output2')
        const response = await fetch(imgsrc)
        const buffer = await response.arrayBuffer()
        const apng = parseAPNG(buffer)
        if (apng instanceof Error){
          console.error('apng.message', apng.message)
          return ;
        }
        await apng.createImages()
        apng.frames.forEach(f => {
          container2.appendChild(f.imageElement)
        })
      })}
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM