JSFiddle - React, Tailwind, and code Playground
JavaScript
//promisify
async function getTimer(t) {
return new Promise((resolve, reject) => {
if (t >= 1000) {
reject(-1)
return
}
setTimeout(() => {
resolve(t)
}, t)
})
}
main()
async function main() {
try {
let t = await getTimer(1000)
console.log(t)
} catch (e) {
console.log(e)
}
}