0.0.4 • Published 11 years ago

channels v0.0.4

Weekly downloads
11,039
License
-
Repository
-
Last release
11 years ago

Example

/*
  Imagine we have an airport with 2 gateways. Every gateway can only be used by one plane at the same time. 
  The planes should land in the order they registered their landing at the airport
*/

var channels = require("channels");

function doLanding(landing, callback)
{
  setTimeout(function()
  {
    console.log(new Date().toString() + " " +landing.planeName + " landed on " + landing.gateway);
    callback();
  },1000);
}

var airport = new channels.channels(doLanding);

airport.emit("gateway1", {planeName: "superjet1", gateway: "gateway1"});
airport.emit("gateway2", {planeName: "superjet2", gateway: "gateway2"});

airport.emit("gateway1", {planeName: "superjet3", gateway: "gateway1"});
airport.emit("gateway2", {planeName: "superjet4", gateway: "gateway2"});

airport.emit("gateway1", {planeName: "superjet5", gateway: "gateway1"});
airport.emit("gateway2", {planeName: "superjet6", gateway: "gateway2"});

Output