diff --git a/lib/task-manager.ts b/lib/task-manager.ts index 761edc0..3ca29a3 100644 --- a/lib/task-manager.ts +++ b/lib/task-manager.ts @@ -173,10 +173,22 @@ export class TaskManager, TStatus extends str } } + private watchProgress(task: TTask, lifecycle: TaskLifecycleStatus) { + let lastProgress = task.progress + const timer = setInterval(() => { + if (task.status !== lifecycle.running) return + if (task.progress === lastProgress) return + lastProgress = task.progress + this.notify() + }, 120) + return () => clearInterval(timer) + } + private async runTask(task: TTask) { const lifecycle = this.getLifecycle(task) as TaskLifecycleStatus task.status = lifecycle.running this.notify() + const stopWatchingProgress = this.watchProgress(task, lifecycle) try { const handler = this.getHandler(task) @@ -198,6 +210,7 @@ export class TaskManager, TStatus extends str this.notify() this.checkAllCompleted() } finally { + stopWatchingProgress() this.activeCount-- if (this.isStarted) setTimeout(() => this.processQueue(), 50) }