Tiny 迭代器驱动
- 支持静态 & 动态优先级
- 支持动态插入任务
- 内置 cpu idle、setTimeout 调度器
TL; DR
import { SingleTask, TaskDriver, IdleScheduler, EVENT, SerialTask } from 'iterator-driver';
const i1 = (function*() {
yield 'x';
})();
const t1 = new SingleTask(i1);
const driver = new TaskDriver(t1, new IdleScheduler(), value => {
console.log(value); // print 'x'
});
driver.on(EVENT.Start, () => {
console.log('It is start!')
});
driver.on(EVENT.Done, () => {
console.log('It is done!')
});
driver.on(EVENT.Cancel, () => {
console.log('It is cancel!')
});
driver.start();
const t1 = new SingleTask(i1, 10);
// or
t1.priority = 20
npm install iterator-driver