Skip to content

Instantly share code, notes, and snippets.

@sergi
Created September 6, 2011 09:51
Show Gist options
  • Save sergi/1197149 to your computer and use it in GitHub Desktop.
Save sergi/1197149 to your computer and use it in GitHub Desktop.
var pasv, pasvReqs;
pasvReqs = function(next, stop) {
pasv = next;
};
pasvReqs(self.processPasv, function(err) { console.log(err) });
var processPasv = function(pasvData) {
console.log("PASVDATA", pasvData);
};
// -----
var enqueue = function(m, c) {
pasv({
mode: m,
callback: c
});
}
@Gozala
Copy link

Gozala commented Sep 6, 2011

// Simplified version of https://github.com/Gozala/streamer/blob/queue/queue.js
function queue() {
  var next, buffer = Array.prototype.slice.call(arguments)

  function enqueue() {
    buffer.push.apply(buffer, arguments)
    if (next && buffer.length) {
      if (false !== next(buffer.shift())) enqueue()
    }
  }

  function stream($, stop) {
     next = $
     enqueue()
  }

  stream.enqueue = enqueue
  return stream
}

@Gozala
Copy link

Gozala commented Sep 6, 2011

var pasvReqs = queue(....)

!function recur() {
    // Take first element from `pasvReqs` and process it via `processElement` black box that will call
   // `recur` once it's done to process next element from the `pasvReqs` queue.
    head(pasvReqs)(function(element) {
       processElement(element, recur)
    })
}()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment