JSFiddle - React, Tailwind, and code Playground
by sandfresh
JavaScript
class Sleep {
constructor(timeout) {
this.timeout = timeout;
}
then(resolve, reject) {
const startTime = Date.now();
console.log("timeout3");
setTimeout(
() => resolve(Date.now() - startTime),
this.timeout
);
}
}
(async () => {
console.log("timeout1");
const sleepTime = await new Sleep(1000);
console.log("timeout2");
console.log(sleepTime);
})();