You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

29 lines
470 B

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
}