-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scheduler):
scheduler
-> interrupter
- 增加task, job, parallel
- Loading branch information
Showing
7 changed files
with
215 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,49 @@ | ||
# @deot/helper-scheduler | ||
|
||
调度器 | ||
调度器 - 进行调度工作的程序 | ||
|
||
### `Task` | ||
创建任务队列,即执行顺序,他是串行的 | ||
|
||
### `Job` | ||
创建任务轮询队列,周期性执行脚本 | ||
|
||
### `Parallel` | ||
创建并行任务执行,可控制并发数 | ||
|
||
### `Interrupter` | ||
中断任务(也可以理解为等待某个任务的完成) | ||
|
||
实现的目的: | ||
这是一段代码使用`await scheduler`调度器 | ||
永远等待它,直到它上面有任何代码执行了`scheduler.next()` | ||
这是一段代码使用`await interrupter`中断器 | ||
永远等待它,直到它上面有任何代码执行了`interrupter.next()` | ||
不论它是同步,微任务,异步执行,之后才会执行它后面的代码 | ||
|
||
### `Scheduler` | ||
```js | ||
import { Scheduler } from '@deot/helper-scheduler'; | ||
import { Interrupter } from '@deot/helper-scheduler'; | ||
``` | ||
```js | ||
// or | ||
import { Scheduler } from '@deot/helper'; | ||
import { Interrupter } from '@deot/helper'; | ||
``` | ||
|
||
```js | ||
const scheduler = Scheduler.of(); | ||
const interrupter = Interrupter.of(); | ||
|
||
scheduler.next(); | ||
await scheduler; | ||
interrupter.next(); | ||
await interrupter; | ||
|
||
Promise.resolve().then(scheduler.next); | ||
await scheduler; | ||
Promise.resolve().then(interrupter.next); | ||
await interrupter; | ||
|
||
setTimeout(scheduler.next); | ||
await scheduler; | ||
setTimeout(interrupter.next); | ||
await interrupter; | ||
|
||
try { | ||
setTimeout(scheduler.nextWithError); | ||
await scheduler; | ||
setTimeout(interrupter.nextWithError); | ||
await interrupter; | ||
} catch { | ||
setTimeout(scheduler.finish); | ||
await scheduler; | ||
setTimeout(interrupter.finish); | ||
await interrupter; | ||
} | ||
``` |
Oops, something went wrong.