Skip to content

Latest commit

 

History

History
36 lines (24 loc) · 619 Bytes

README.md

File metadata and controls

36 lines (24 loc) · 619 Bytes

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');