From 79c62d6eb56df7955e69dc492c7dce3311b6445d Mon Sep 17 00:00:00 2001 From: Jonathan Garcia Date: Thu, 6 Jun 2024 07:26:42 -0700 Subject: [PATCH] quick promise practice --- apply/setinterval.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 apply/setinterval.js diff --git a/apply/setinterval.js b/apply/setinterval.js new file mode 100644 index 0000000..64f1d88 --- /dev/null +++ b/apply/setinterval.js @@ -0,0 +1,25 @@ +// const setCancellableInterval = (cb, dur, ...args) => { + +// const timerId = setInterval(() => cb.apply(null, args), dur) +// return () => clearInterval(timerId) +// } + +// let i = 0; + +// const cancel = setCancellableInterval(() => { +// i++; +// }, 10); + +// cancel(); // Called at t = 25 +// console.log(i) + + + +function promiseFactory(cb) { + return new Promise(cb) +} + +(async function () { + const boom = await promiseFactory((res, rej) => setTimeout(() => res(123), 2000)) + console.log(boom) +})() \ No newline at end of file