UNPKG

async-to-sync

Version:

async-to-sync is help you for Javascript asynchronous function to synchronous function.

11 lines 300 B
const ats = (arrCallback, fallback) => { const promise = cb => new Promise(res => cb(res)); (async() => { try { for(const cb of arrCallback) await promise(cb) } catch(e) { if(typeof fallback !== 'function') return console.error('Error:', e); fallback(); } })(); };