canjs / can-queues

A light weight JavaScript task queue
https://canjs.com/doc/can-queues.html
MIT License
2 stars 2 forks source link

Make a slow mode #15

Open justinbmeyer opened 6 years ago

justinbmeyer commented 6 years ago

It can be hard to digest what's going on as a result of can.queues.log("flush").

I propose the ability to turn on a slow mode to help see what happens as consequence of an action.

This might be unnecessary once the debugging tools are available. However, this would be easy and helpful.

In short, if someone runs:

can.queues.startSlow(1000);

This will run only one task every 1000ms.

If someone runs:

can.queues.stopSlow()

This will resume running all tasks synchronously.

Potential problems

Currently, the task queue can "run over itself". Meaning that if someone does:

queues.enqueueByQueue({
  notify: [function(){
    console.log("notifyA");

    queues.enqueueByQueue({ notify: [ console.log ] }, null, [ "notifyB"] );
    console.log("notifyC");
  }],
  derive: [function(){
    console.log("derive");
  }]
})

This might log:

notifyA
notifyB
notifyC
derive

Slow mode will likely change this to:

notifyA
notifyC
notifyB
derive