Sha256: 90f5ae355361f8fecc2a93a113e077577d5b20d5ba3a84116f397c0625ffbdff

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 KB

Contents

var Linda = function(io, opts){
  var self = this;
  this.io = null;
  if(io === null || typeof io === "undefined"){
    this.io = new RocketIO().connect();
  }
  else{
    this.io = io;
  }
  this.opts = opts || {};
  this.TupleSpace = function(name){
    if(name === null || typeof name !== "string") name = "__default__";
    this.name = name;
    this.linda = self;
    var space = this;
    var make_callback_id = function(){
      return new Date()-0+"_"+Math.floor(Math.random()*1000000);
    };
    this.write = function(tuple, opts){
      if(tuple === null || typeof tuple !== "object") return;
      if(opts === null || typeof opts === "undefined") opts = {};
      self.io.push("__linda_write", [space.name, tuple, opts]);
    };
    this.read = function(tuple, callback){
      if(tuple === null || typeof tuple !== "object") return;
      if(typeof callback !== "function") return;
      var callback_id = make_callback_id();
      self.io.once("__linda_read_callback_"+callback_id, function(data){
        callback(data.tuple, data.info);
      });
      self.io.push("__linda_read", [space.name, tuple, callback_id]);
    };
    this.take = function(tuple, callback){
      if(tuple === null || typeof tuple !== "object") return;
      if(typeof callback !== "function") return;
      var callback_id = make_callback_id();
      self.io.once("__linda_take_callback_"+callback_id, function(data){
        callback(data.tuple, data.info);
      });
      self.io.push("__linda_take", [space.name, tuple, callback_id]);
    };
    this.watch = function(tuple, callback){
      if(tuple === null || typeof tuple !== "object") return;
      if(typeof callback !== "function") return;
      var callback_id = make_callback_id();
      self.io.on("__linda_watch_callback_"+callback_id, function(data){
        callback(data.tuple, data.info);
      });
      self.io.push("__linda_watch", [space.name, tuple, callback_id]);
    };
  };
};

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sinatra-rocketio-linda-1.0.1 lib/js/linda.js
sinatra-rocketio-linda-1.0.0 lib/js/linda.js