示例#1
0
  it("can run a tail on a remote operation stream", function(next) {
    var em = new EventEmitter();
    var bus = ros(em.on.bind(em, "message"), em.emit.bind(em, "message"), mesh.tailable(mesh.limit(1, mesh.wrap(function(operation, next) {
      next(void 0, operation);
    })), function() {
      return true;
    }));

    var ops;

    var tail = bus(mesh.op("tail"))
    .pipe(_.pipeline(_.collect))
    .on("data", function(data) {
      ops = data;
    });

    bus(mesh.op("insert"));
    bus(mesh.op("insert"));
    bus(mesh.op("insert"));
    bus(mesh.op("insert")).on("end", function() {
      tail.end();
      setTimeout(function() {
        expect(ops.length).to.be(4);
        next();
      }, 10);
    });
  });
示例#2
0
  xit("doesn't re-emit the same incomming operation", function(next) {
    var i = 0;
    var em = new EventEmitter();
    var bus = ros(em.on.bind(em, "message"), em.emit.bind(em, "message"), mesh.wrap(function(operation, next) {
      i++;
      next(void 0, operation);
    }));

    bus = mesh.tailable(bus);
    bus(mesh.op("tail")).pipe(mesh.open(bus));


    em.emit("message", mesh.op("abba"));

    setTimeout(function() {
      expect(i).to.be(0);
      return next();
    }, 1);
  });
示例#3
0
var mesh    = require("mesh");
var storage = require("mesh-memory");
var io      = require("mesh-socket.io");

// storage. This can be anything- mongodb, memory, etc.
var bus = storage();

// allows the app to receive all operations executed on DB.
bus = mesh.tailable(bus);

// make the bus realtime with socket.io
bus = mesh.parallel(bus, io({ channel: "operation" }, bus));

// tail for all local & remote operations
bus(mesh.op("tail"))
.on("data", function(data) {
  console.log("new message: ", data);
});

bus({
  name: "insert",
  collection: "messages",
  data: {
    text: prompt("Type a message!")
  }
});