@leafer/task 1.0.0-beta.5 → 1.0.0-beta.7
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 +4 -4
- package/src/TaskProcessor.ts +14 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/task",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.7",
|
|
4
4
|
"description": "@leafer/task",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"leaferjs"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@leafer/math": "1.0.0-beta.
|
|
23
|
-
"@leafer/debug": "1.0.0-beta.
|
|
22
|
+
"@leafer/math": "1.0.0-beta.7",
|
|
23
|
+
"@leafer/debug": "1.0.0-beta.7"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@leafer/interface": "1.0.0-beta.
|
|
26
|
+
"@leafer/interface": "1.0.0-beta.7"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/TaskProcessor.ts
CHANGED
|
@@ -21,6 +21,7 @@ export class TaskProcessor implements ITaskProcessor {
|
|
|
21
21
|
|
|
22
22
|
public get running(): boolean { return this._running }
|
|
23
23
|
private _running: boolean
|
|
24
|
+
private _timer: any
|
|
24
25
|
|
|
25
26
|
public get percent(): number {
|
|
26
27
|
const { total } = this
|
|
@@ -49,7 +50,7 @@ export class TaskProcessor implements ITaskProcessor {
|
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
public get remain(): number {
|
|
52
|
-
return this._isComplete ?
|
|
53
|
+
return this._isComplete ? this.total : this.total - this.finishedIndex
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
|
|
@@ -58,16 +59,15 @@ export class TaskProcessor implements ITaskProcessor {
|
|
|
58
59
|
this.init()
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
|
|
62
62
|
protected init(): void {
|
|
63
63
|
this.empty()
|
|
64
|
-
this.index = 0
|
|
65
|
-
this.parallelSuccessNumber = 0
|
|
66
64
|
this._running = false
|
|
67
65
|
this._isComplete = true
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
protected empty(): void {
|
|
69
|
+
this.index = 0
|
|
70
|
+
this.parallelSuccessNumber = 0
|
|
71
71
|
this.list = []
|
|
72
72
|
this.parallelList = []
|
|
73
73
|
}
|
|
@@ -79,6 +79,7 @@ export class TaskProcessor implements ITaskProcessor {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
public pause(): void {
|
|
82
|
+
clearTimeout(this._timer)
|
|
82
83
|
this._running = false
|
|
83
84
|
}
|
|
84
85
|
|
|
@@ -94,7 +95,9 @@ export class TaskProcessor implements ITaskProcessor {
|
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
public stop(): void {
|
|
98
|
+
clearTimeout(this._timer)
|
|
97
99
|
this._running = false
|
|
100
|
+
this._isComplete = true
|
|
98
101
|
this.list.forEach(item => {
|
|
99
102
|
item.complete()
|
|
100
103
|
})
|
|
@@ -219,24 +222,27 @@ export class TaskProcessor implements ITaskProcessor {
|
|
|
219
222
|
})
|
|
220
223
|
|
|
221
224
|
}
|
|
225
|
+
|
|
222
226
|
}
|
|
223
227
|
|
|
224
228
|
} else {
|
|
225
229
|
|
|
226
230
|
this.index += this.parallelSuccessNumber
|
|
231
|
+
this.parallelSuccessNumber = 0
|
|
227
232
|
this.nextTask()
|
|
228
233
|
|
|
229
234
|
}
|
|
230
235
|
}
|
|
231
236
|
|
|
232
237
|
private nextTask(): void {
|
|
233
|
-
|
|
234
|
-
this.
|
|
235
|
-
}
|
|
238
|
+
if (this.total === this.finishedIndex) {
|
|
239
|
+
this.onComplete()
|
|
240
|
+
} else {
|
|
241
|
+
this._timer = setTimeout(() => this.run(), 0)
|
|
242
|
+
}
|
|
236
243
|
}
|
|
237
244
|
|
|
238
245
|
private onComplete(): void {
|
|
239
|
-
this._isComplete = true
|
|
240
246
|
this.stop()
|
|
241
247
|
if (this.config.onComplete) this.config.onComplete()
|
|
242
248
|
}
|
|
@@ -244,7 +250,6 @@ export class TaskProcessor implements ITaskProcessor {
|
|
|
244
250
|
private onTask(task: TaskItem): void {
|
|
245
251
|
task.complete()
|
|
246
252
|
if (this.config.onTask) this.config.onTask()
|
|
247
|
-
if (this.finishedIndex + 1 === this.total) this.onComplete()
|
|
248
253
|
}
|
|
249
254
|
|
|
250
255
|
private onParallelError(error: unknown): void {
|