perf(runtime-core): avoid duplicate postFlushCb invocation

Also improve flush performance by using for loop instead of shift()

fix #1595
This commit is contained in:
Evan You
2020-07-15 22:36:41 -04:00
parent aab99abd28
commit 165068dbc2
2 changed files with 49 additions and 14 deletions

View File

@@ -278,4 +278,20 @@ describe('scheduler', () => {
await nextTick()
expect(calls).toEqual(['job3', 'job2', 'job1'])
})
// #1595
test('avoid duplicate postFlushCb invocation', async () => {
const calls: string[] = []
const cb1 = () => {
calls.push('cb1')
queuePostFlushCb(cb2)
}
const cb2 = () => {
calls.push('cb2')
}
queuePostFlushCb(cb1)
queuePostFlushCb(cb2)
await nextTick()
expect(calls).toEqual(['cb1', 'cb2'])
})
})