jessetane / queue

Asynchronous function queue with adjustable concurrency
MIT License
764 stars 66 forks source link

abortable tasks #32

Closed TomKaltz closed 7 years ago

TomKaltz commented 7 years ago

Might be nice to have abortable tasks. Another queue library allows you to return an abject with an abort function like this...

function delayedHello(callback) {
  var id = setTimeout(function() {
    console.log("Hello")
    callback(null);
  }, delay)
  return {
    abort: function() {
      clearTimeout(id)
    }
  }
}

I guess another option could be to just queue.once('end',...) from within your task if any cleanups need to be done. Although it's ambiguous when the end event occurs whether you've aborted or the queue has finished all tasks. Perhaps a special event for when a queue is ended manually? Should end() be renamed to abort()? Sorry for my stream of consciousness. Any thoughts @jessetane?

jessetane commented 7 years ago

Queue should already handle "aborted" tasks for you - check out the internal .session property. Reopen if you're talking about something else.