Home > OS >  Extend class that uses a nested callback style and write new class using async await?
Extend class that uses a nested callback style and write new class using async await?

Time:10-26

Can I extend classes that uses a nested callback style and write the child class using async await? Will there be issues?

Working with legacy code but would rather work in async await style to get this done quickly since that's what I know.

CodePudding user response:

Yes you can. There should not be issues at all - you can built-in apis like promisify Initially all callbacks could be converted to promises in this style:

const promise = () => {
 return new Promise((resolve, reject) => {
   doStuff((err, data) => {
     if (err) reject(err);
     else resolve(data);
   })
 })
}

await promise();
  • Related