return function(operation) {
    var i = 0;

    var stream = new Writable();

    process.nextTick(function() {

      function run() {
        if (i >= dbs.length) return stream.end();
        var db = dbs[i++];
        var found = false;
        db(operation).on("data", function(data) {
          found = true;
          stream.write(data);
        }).on("end", function() {
          if (found) {
            return stream.end();
          } else {
            return run();
          }
        });
      }
      run();
    });

    return stream.reader;
  };
 function run() {
   if (i >= dbs.length) return stream.end();
   var db = dbs[i++];
   db(operation).on("data", function(data) {
     stream.write(data);
   }).on("end", run);
 }
 }).on("end", function() {
   if (found) {
     return stream.end();
   } else {
     return run();
   }
 });
  function _write() {
    if (running) return;

    if (buffer.length) {
      running = true;
      return write.call(through, buffer.shift(), function() {
        running = false;
        _write();
      });
    }

    if (ended) {
      dstWriter.end();
    }
  }
 function run() {
   if (i >= dbs.length) return stream.end();
   var db = dbs[i++];
   var found = false;
   db(operation).on("data", function(data) {
     found = true;
     stream.write(data);
   }).on("end", function() {
     if (found) {
       return stream.end();
     } else {
       return run();
     }
   });
 }
  return function(operation) {
    var i = 0;

    var stream = new Writable();

    process.nextTick(function() {
      function run() {
        if (i >= dbs.length) return stream.end();
        var db = dbs[i++];
        db(operation).on("data", function(data) {
          stream.write(data);
        }).on("end", run);
      }
      run();
    });

    return stream.reader;
  };
  return function(operation) {
    var i = 0;
    var self = this;

    var stream = new Writable();

    process.nextTick(function() {
      dbs.forEach(function(db) {
        db(operation).on("data", function(data) {
          stream.write(data);
        }).on("end", function() {
          if (++i >= dbs.length) {
            return stream.end();
          }
        });
      });
    });

    return stream.reader;
  };
module.exports = function(write, end) {

  var dstWriter = new Writable();
  var srcWriter = new Writable();
  var stream    = new Stream(dstWriter.reader, srcWriter);
  var through   = new Through(dstWriter);

  var buffer  = [];
  var running = false;
  var ended   = false;

  function _write() {
    if (running) return;

    if (buffer.length) {
      running = true;
      return write.call(through, buffer.shift(), function() {
        running = false;
        _write();
      });
    }

    if (ended) {
      dstWriter.end();
    }
  }

  srcWriter.reader.on("data", function(data) {
    buffer.push(data);
    _write();
  }).on("end", function() {
    ended = true;
    _write();
  });

  return stream;
};
 db(operation).on("data", function(data) {
   found = true;
   stream.write(data);
 }).on("end", function() {
 db(operation).on("data", function(data) {
   stream.write(data);
 }).on("end", run);
 }).on("end", function() {
   if (++i >= dbs.length) {
     return stream.end();
   }
 });
Esempio n. 12
0
 db(name, properties).on("data", function(data) {
   stream.write(data);
 }).on("end", function() {