Skip to content

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