Flush your callbacks on the next event loop tick
From CDN:
import nextTick from 'https://cdn.jsdelivr.net/gh/LosMaquios/next-tick/index.js'
From NPM:
$ npm install next-tick
nextTick(() => {
console.log(' deferred')
})
console.log('Execution')
// Output: Execution deferred
nextTick(callback)
Defers execution of a given callback
nextTick.waiting
A boolean indicating when we are waiting to flush callbacks
nextTick.queue
An array containing callbacks to be flushed
nextTick.flush()
Flush callbacks as a single microtask
nextTick.afterFlush(callback)
Execute (as a macrotask) a callback after flushing the queue