fast-forward-timer
v0.0.1
Published
受到`jest.advanceTimersByTime(msToRun)`的启发,实现的可以快进延迟的`setTimeout`
Downloads
4
Readme
fast-forward-timer
受到jest.advanceTimersByTime(msToRun)
的启发,实现的可以快进延迟的setTimeout
安装
npm i fast-forward-timer -save
brower
import { fSetTimeout, forwardAll } from 'fast-forward-timer';
const timer1 = fSetTimeout(() => {
console.log(1);
}, 3000);
timer1.forward(2000); // 快进2s
timer.delay(500); // 延迟0.5s
const timer2 = fSetTimeout(() => {
console.log(2);
}, 2000);
forwardAll(1000); // 所有定时器快进1s
// 结果:0.5s -> 1 -> 1s -> 2
node
const { fSetTimeout, forwardAll } = require('fast-forward-timer');