Q:

Write a JavaScript program to convert an asynchronous function to return a promise

0

Write a JavaScript program to convert an asynchronous function to return a promise

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const promisify = func => (...args) =>
  new Promise((resolve, reject) =>
    func(...args, (err, result) => (err ? reject(err) : resolve(result)))
  );
const delay = promisify((d, cb) => setTimeout(cb, d));
delay(2000).then(() => console.log('Hi!')); // // Promise resolves after 2s

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now