All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.src.nextTick.js Maven / Gradle / Ivy

There is a newer version: 3.14.1
Show newest version

let tickStack = []

let isHolding = false

export function nextTick(callback = () => {}) {
  queueMicrotask(() => {
    isHolding || setTimeout(() => {
      releaseNextTicks()
    })
  })

  return new Promise((res) => {
    tickStack.push(() => {
        callback();
        res();
    });
  })
}

export function releaseNextTicks() {
    isHolding = false

    while (tickStack.length) tickStack.shift()()
}

export function holdNextTicks() {
    isHolding = true
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy