Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

cleaning up unused transactor code

  • Loading branch information...
commit ddcae88bf1db5baf6fe1530f7b45de073309daa0 1 parent c640c97
ethersheet-collective authored

Showing 1 changed file with 9 additions and 27 deletions. Show diff stats Hide diff stats

  1. +9 27 transactor.js
36 transactor.js
... ... @@ -1,27 +1,15 @@
1   -var inherits = require('util').inherits;
2   -var EventEmitter = require('events').EventEmitter;
3   -
4   -var Transactor = function(server,transaction_handler){
5   - this.transaction_handler = transaction_handler || this.defaultEventHandler;
  1 +var Transactor = function(o){
  2 + o = o || {};
  3 + if(typeof o.transaction_handler === 'function'){
  4 + this.onTransaction(o.transaction_handler);
  5 + }
6 6 this.sockets = {};
7   - if(server) this.setServer(server);
8 7 };
9 8
10   -inherits(Transactor,EventEmitter);
11 9 module.exports = Transactor;
12 10
13   -// handler interface: function eventHandler(... data,cb)
14   -// callback interface: function cb(err,data)
15   -Transactor.prototype.defaultEventHandler = function(){
16   - arguments[arguments.length - 1](null,arguments[arguments.length - 2]);
17   -};
18   -
19   -Transactor.prototype.setServer = function(server){
20   - var trans = this;
21   - this.server = server;
22   - this.server.on('connection', function(socket){
23   - trans.addSocket(socket);
24   - });
  11 +Transactor.prototype.onTransaction = function(transaction_handler){
  12 + this.transaction_handler = transaction_handler;
25 13 };
26 14
27 15 Transactor.prototype.addSocket = function(channel,socket){
@@ -35,23 +23,17 @@ Transactor.prototype.addSocket = function(channel,socket){
35 23 socket.on('data',function(data){
36 24 trans.transaction_handler(channel,data,function(err,data){
37 25 if(err) return socket.error(err,data);
38   - trans.tellAll(channel,data);
  26 + trans.broadcast(channel,data);
39 27 });
40 28 });
41 29
42 30 // add the supplied disconnection handler
43 31 socket.on('close', function(){
44   - if(err) throw err;
45   - trans.emit('close',channel,socket);
46 32 });
47 33
48 34 };
49 35
50   -Transactor.prototype.onTransaction = function(transaction_handler){
51   - this.transaction_handler = transaction_handler;
52   -};
53   -
54   -Transactor.prototype.tellAll = function(channel,data){
  36 +Transactor.prototype.broadcast = function(channel,data){
55 37 if(!this.sockets[channel]) return;
56 38 this.sockets[channel].forEach(function(socket){
57 39 socket.write(data);

0 comments on commit ddcae88

Please sign in to comment.
Something went wrong with that request. Please try again.