@leafer/task 1.0.0-beta.12 → 1.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -5
- package/src/TaskProcessor.ts +6 -2
- package/types/index.d.ts +54 -0
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/task",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.16",
|
|
4
4
|
"description": "@leafer/task",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.ts",
|
|
8
|
+
"types": "types/index.d.ts",
|
|
8
9
|
"files": [
|
|
9
|
-
"src"
|
|
10
|
+
"src",
|
|
11
|
+
"types",
|
|
12
|
+
"dist"
|
|
10
13
|
],
|
|
11
14
|
"repository": {
|
|
12
15
|
"type": "git",
|
|
@@ -19,10 +22,10 @@
|
|
|
19
22
|
"leaferjs"
|
|
20
23
|
],
|
|
21
24
|
"dependencies": {
|
|
22
|
-
"@leafer/math": "1.0.0-beta.
|
|
23
|
-
"@leafer/debug": "1.0.0-beta.
|
|
25
|
+
"@leafer/math": "1.0.0-beta.16",
|
|
26
|
+
"@leafer/debug": "1.0.0-beta.16"
|
|
24
27
|
},
|
|
25
28
|
"devDependencies": {
|
|
26
|
-
"@leafer/interface": "1.0.0-beta.
|
|
29
|
+
"@leafer/interface": "1.0.0-beta.16"
|
|
27
30
|
}
|
|
28
31
|
}
|
package/src/TaskProcessor.ts
CHANGED
|
@@ -24,7 +24,7 @@ export class TaskProcessor implements ITaskProcessor {
|
|
|
24
24
|
|
|
25
25
|
public index = 0
|
|
26
26
|
|
|
27
|
-
public delayNumber = 0
|
|
27
|
+
public delayNumber = 0 // 延迟执行任务
|
|
28
28
|
|
|
29
29
|
public get finishedIndex(): number {
|
|
30
30
|
return this.isComplete ? 0 : this.index + this.parallelSuccessNumber
|
|
@@ -157,6 +157,10 @@ export class TaskProcessor implements ITaskProcessor {
|
|
|
157
157
|
|
|
158
158
|
protected runTask(): void {
|
|
159
159
|
const task = this.list[this.index]
|
|
160
|
+
if (!task) {
|
|
161
|
+
this.nextTask() // 存在延时任务
|
|
162
|
+
return
|
|
163
|
+
}
|
|
160
164
|
task.run().then(() => {
|
|
161
165
|
|
|
162
166
|
this.onTask(task)
|
|
@@ -232,7 +236,7 @@ export class TaskProcessor implements ITaskProcessor {
|
|
|
232
236
|
|
|
233
237
|
task = this.list[nextIndex]
|
|
234
238
|
|
|
235
|
-
if (task.parallel) {
|
|
239
|
+
if (task && task.parallel) {
|
|
236
240
|
parallelList.push(task)
|
|
237
241
|
this.runParallelTask(task)
|
|
238
242
|
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ITaskProcessor, ITaskProcessorConfig, ITaskItem, IFunction, ITaskOptions } from '@leafer/interface';
|
|
2
|
+
|
|
3
|
+
declare class TaskProcessor implements ITaskProcessor {
|
|
4
|
+
config: ITaskProcessorConfig;
|
|
5
|
+
protected list: ITaskItem[];
|
|
6
|
+
protected parallelList: ITaskItem[];
|
|
7
|
+
protected parallelSuccessNumber: number;
|
|
8
|
+
running: boolean;
|
|
9
|
+
isComplete: boolean;
|
|
10
|
+
protected timer: any;
|
|
11
|
+
get total(): number;
|
|
12
|
+
index: number;
|
|
13
|
+
delayNumber: number;
|
|
14
|
+
get finishedIndex(): number;
|
|
15
|
+
get remain(): number;
|
|
16
|
+
get percent(): number;
|
|
17
|
+
constructor(config?: ITaskProcessorConfig);
|
|
18
|
+
add(taskCallback: IFunction, options?: ITaskOptions | number): ITaskItem;
|
|
19
|
+
protected push(task: ITaskItem, start?: boolean): void;
|
|
20
|
+
protected empty(): void;
|
|
21
|
+
start(): void;
|
|
22
|
+
pause(): void;
|
|
23
|
+
resume(): void;
|
|
24
|
+
skip(): void;
|
|
25
|
+
stop(): void;
|
|
26
|
+
protected run(): void;
|
|
27
|
+
protected runTask(): void;
|
|
28
|
+
protected runParallelTasks(): void;
|
|
29
|
+
protected runParallelTask(task: ITaskItem): void;
|
|
30
|
+
private nextTask;
|
|
31
|
+
protected setParallelList(): void;
|
|
32
|
+
protected fillParallelTask(): void;
|
|
33
|
+
protected onComplete(): void;
|
|
34
|
+
protected onTask(task: ITaskItem): void;
|
|
35
|
+
protected onParallelError(error: unknown): void;
|
|
36
|
+
protected onError(error: unknown): void;
|
|
37
|
+
destroy(): void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare class TaskItem implements ITaskItem {
|
|
41
|
+
readonly id: number;
|
|
42
|
+
parent: TaskProcessor;
|
|
43
|
+
parallel: boolean;
|
|
44
|
+
time: number;
|
|
45
|
+
isComplete: boolean;
|
|
46
|
+
isCancel: boolean;
|
|
47
|
+
private task;
|
|
48
|
+
constructor(task?: IFunction);
|
|
49
|
+
run(): Promise<void>;
|
|
50
|
+
complete(): void;
|
|
51
|
+
cancel(): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { TaskItem, TaskProcessor };
|