Created
April 13, 2023 19:28
-
-
Save rodrigok/0e74fa9a6c50131d9c0ed420c83fc5eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// node --version v18.16.0 | |
import deasync from 'deasync'; | |
import fetch from 'node-fetch'; | |
function deasyncPromise(fn) { | |
return (...args) => { | |
return deasync((cb) => fn(...args).then((r) => cb(undefined, r)).catch(cb))(); | |
} | |
} | |
async function asyncFlow(url) { | |
const response = await fetch(url); | |
// throw new Error('asd'); | |
return response.text(); | |
} | |
console.log('beginning') | |
setInterval(() => { | |
console.log("loop", Date.now()); | |
}, 200); | |
const as = function() { | |
console.log('async start'); | |
console.log(deasyncPromise(asyncFlow)('https://open.rocket.chat/api/info')); | |
console.log('async end'); | |
} | |
process.nextTick(as); | |
console.log('end'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment