Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add active() and count() methods to po.queue #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

straup
Copy link

@straup straup commented Aug 18, 2011

Prettymaps uses these to display a handy dialog indicating the number of tiles left to load.

@shawnbot
Copy link
Contributor

+1. I went one step further and added "process" events for queuing in an experimental version of polymaps a while back, which makes it trivial to add a progress spinner to any page with polymaps on it. Does this seem worth adding?

po.queue = (function() {
  var queued = [], active = 0, size = 6;
  var queue = {};
  queue.dispatch = po.dispatch(queue);

  function process() {
    if ((active >= size) || !queued.length) {
    } else {
      active++;
      queued.pop()();
    }
    queue.dispatch({type: "process", active: active, queued: queued.length});
  }

  function dequeue(send) {
    for (var i = 0; i < queued.length; i++) {
      if (queued[i] == send) {
        queued.splice(i, 1);
        queue.dispatch({type: "process", active: active, queued: queued.length});
        return true;
      }
    }
    return false;
  }
  ...

@mbostock
Copy link
Contributor

Do you need both methods? I wonder if it'd be simpler to have a size() method that returns queued.length + active.

@straup
Copy link
Author

straup commented Aug 18, 2011

Strictly speaking, both methods aren't necessary but I there may be cases where people don't care what the size of the queue is only that it's being processed. I needed the size of the queue do display some amount of feedback and "active" is/was already being passed around to maintain state so I just decided to check that first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants