diff --git a/lib/index.js b/lib/index.js index d6002d7..d9942dd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -111,8 +111,12 @@ module.exports = (limit) => { const step = this.steps[this.steps.keys()[task.step]] task.state = 'running' + const thisStep = task.step task.timeout = setTimeout(() => { + if (task.step !== thisStep) { + return + } if (task.abort && task.abort.constructor === Function) { task.abort() } @@ -123,10 +127,16 @@ module.exports = (limit) => { task.abort = step.run( task, data => { + if (task.step !== thisStep) { + return + } task.completeStep(data) this.debounceRun() }, error => { + if (task.step !== thisStep) { + return + } task.error(error) this.debounceRun() }