Comments (4)
To clarify why I find this behaviour surprising, imagine that I'd want to put do some clean up in await/awaitAll that is only worth running when all async tasks are truly finished.
from d3-queue.
This is the expected behavior.
You’ve defined a queue with a concurrency of 1. Thus, when you first call queue.defer, it starts your first longRunningTask
. However, the second call to queue.defer does not start the second task because the first task is still running, and 2 > 1. Your tasks are not abortable, so once they start, there is no way to cancel them.
When you then abort the queue, the second task is still not started, but the await callback is immediately invoked with an error. (Per the queue.abort documentation: “invokes the queue.await or queue.awaitAll callback with an error indicating that the queue was aborted.”) You’re ignoring this error, but if you only want to do something if your tasks complete (successfully), then you need to check for the error instead, like this:
q.await(function(error) {
if (error) throw error;
console.log("all done");
});
Then you’d see this output:
Error: abort
at Object.q.abort (…/node_modules/d3-queue/build/d3-queue.js:90:34)
at null._onTimeout (repl:1:27)
at Timer.listOnTimeout (timers.js:92:15)
task finished
Again, the only way to avoid the “task finished” message is to make your tasks abortable, and to abort the queue before they finish; otherwise there is no way of aborting them, short of terminating the entire process.
If you want to “abort” the queue in the sense of letting any running tasks finish without letting any further pending tasks start, well, that’s not what queue.abort does. But I suppose you could set a sentinel value that your longRunningTask
could check on start, and they could immediately invoke the callback with a null result rather than doing any actual work.
from d3-queue.
I’ve expanded the documentation for queue.abort.
I could maybe imagine a queue.cancel method which lets running tasks complete but doesn’t allow pending tasks to start. Something like this:
cancel: function() {
if (error == null) waiting = NaN;
return q;
}
But I haven’t tested it.
from d3-queue.
That cancel method sounds like what I'm after. Thanks for considering it!
from d3-queue.
Related Issues (20)
- If a task errors, active tasks should be aborted. HOT 1
- Handle synchronous errors. HOT 1
- Support for tasks that depend on previous results. HOT 1
- Support for indefinitely-long queues. HOT 1
- Support for promises. HOT 1
- d3_queue Uncaught Error HOT 3
- The keyword 'await' is reserved HOT 24
- Uncaught TypeError: d3.queue is not a function HOT 2
- queue.js has errors when processed with ES2015 HOT 2
- Clarify the difference between await() and awaitAll() HOT 1
- .progress() or .tick() method? HOT 2
- Errors thrown inside .await() are silenced HOT 1
- The keyword 'await' is reserved HOT 2
- .awaitAll calling early HOT 2
- bind variable to .await() HOT 2
- Cannot catch 422 errors HOT 4
- Array of queues with one awaitAll HOT 6
- Uncaught TypeError: d3.queue is not a function D3v5 vanilla HOT 2
- Allow "defer after await" at any time before notification triggered HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-queue.