Skip to content

Instantly share code, notes, and snippets.

@rodrigok
Created April 13, 2023 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigok/0e74fa9a6c50131d9c0ed420c83fc5eb to your computer and use it in GitHub Desktop.
Save rodrigok/0e74fa9a6c50131d9c0ed420c83fc5eb to your computer and use it in GitHub Desktop.
// 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