@leafer/task 1.9.10 → 1.9.12
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 +16 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/task",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.12",
|
|
4
4
|
"description": "@leafer/task",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/math": "1.9.
|
|
26
|
-
"@leafer/debug": "1.9.
|
|
25
|
+
"@leafer/math": "1.9.12",
|
|
26
|
+
"@leafer/debug": "1.9.12"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.9.
|
|
29
|
+
"@leafer/interface": "1.9.12"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/TaskProcessor.ts
CHANGED
|
@@ -159,9 +159,16 @@ export class TaskProcessor implements ITaskProcessor {
|
|
|
159
159
|
protected runTask(): void {
|
|
160
160
|
const task = this.list[this.index]
|
|
161
161
|
if (!task) {
|
|
162
|
-
this.nextTask()
|
|
162
|
+
this.timer = setTimeout(() => this.nextTask()) // 存在延时任务
|
|
163
163
|
return
|
|
164
164
|
}
|
|
165
|
+
|
|
166
|
+
if (task.isCancel) {
|
|
167
|
+
this.index++
|
|
168
|
+
this.runTask()
|
|
169
|
+
return
|
|
170
|
+
}
|
|
171
|
+
|
|
165
172
|
task.run().then(() => {
|
|
166
173
|
|
|
167
174
|
this.onTask(task)
|
|
@@ -199,19 +206,19 @@ export class TaskProcessor implements ITaskProcessor {
|
|
|
199
206
|
|
|
200
207
|
protected setParallelList(): void {
|
|
201
208
|
let task: ITaskItem
|
|
209
|
+
const { config, list, index } = this
|
|
202
210
|
|
|
203
211
|
this.parallelList = []
|
|
204
212
|
this.parallelSuccessNumber = 0
|
|
205
|
-
let end =
|
|
213
|
+
let end = index + config.parallel
|
|
206
214
|
|
|
207
|
-
if (end >
|
|
215
|
+
if (end > list.length) end = list.length
|
|
208
216
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
this.parallelList.push(task)
|
|
213
|
-
|
|
214
|
-
break
|
|
217
|
+
if (config.parallel > 1) {
|
|
218
|
+
for (let i = index; i < end; i++) {
|
|
219
|
+
task = list[i]
|
|
220
|
+
if (task.parallel) this.parallelList.push(task)
|
|
221
|
+
else break
|
|
215
222
|
}
|
|
216
223
|
}
|
|
217
224
|
}
|