soldair / node-qrcode

qr code generator
MIT License
7.46k stars 621 forks source link

callback function delays to execute #350

Open coucoseth opened 1 year ago

coucoseth commented 1 year ago
QRCode.toDataURL(dataForQRCode)
.then(url => {
 console.log(url)
})
.catch(err => {
     console.error('qrcode error', err)
 })
 // other piece of code

The other piece of code gets executed before the callback of QRCode . How can i make sure it executes only after the qrcode url is returned

joshxyzhimself commented 1 year ago
(async () => {
  try {
    const url = await QRCode.toDataURL(dataForQRCode);
    // other piece of code
  } catch (e) {
    console.error(e);
  }
})();