From e7ad8ab4b0b0d5301a0e113e810ac4d7751c43c4 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 29 Jun 2009 14:11:01 +0200 Subject: [PATCH] Clean up some of the event handling code --- src/events.js | 6 +----- src/file.js | 31 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/events.js b/src/events.js index e534ff3..928dd61 100644 --- a/src/events.js +++ b/src/events.js @@ -27,11 +27,7 @@ emitter.emit = function (type, args) { var length = listeners.length; for (var i = 0; i < length; i++) { - if (args) { - listeners[i].apply(this, args); - } else { - listeners[i].call(this); - } + listeners[i].apply(this, args); } }; diff --git a/src/file.js b/src/file.js index b1922b2..c36c6aa 100644 --- a/src/file.js +++ b/src/file.js @@ -63,7 +63,8 @@ node.fs.File = function (options) { promise.method = method; promise.args = args; - //node.debug("add action: " + JSON.stringify(action)); + //node.debug("add action " + method + " " + JSON.stringify(args)); + actionQueue.push(promise); // If the queue was empty, immediately call the method. @@ -75,24 +76,20 @@ node.fs.File = function (options) { function act () { var promise = actionQueue[0]; // peek at the head of the queue if (promise) { - node.debug("internal apply " + JSON.stringify(promise.args)); + //node.debug("internal apply " + JSON.stringify(promise.args)); internal_methods[promise.method].apply(self, promise.args); } } // called after each action finishes (when it returns from the thread pool) function success () { + //node.debug("success called"); + var promise = actionQueue[0]; if (!promise) throw "actionQueue empty when it shouldn't be."; - var args = []; - for (var i = 0; i < arguments.length; i++) { - node.debug(JSON.stringify(arguments[i])); - args.push(arguments[i]); - } - - promise.emitSuccess(args); + promise.emitSuccess(arguments); actionQueue.shift(); act(); @@ -103,13 +100,8 @@ node.fs.File = function (options) { if (!promise) throw "actionQueue empty when it shouldn't be."; - var args = []; - for (var i = 0; i < arguments.length; i++) { - args.push(arguments[i]); - } - - promise.emitError(args); - self.emitError(args); + promise.emitError(arguments); + self.emitError(arguments); } var internal_methods = { @@ -167,6 +159,7 @@ node.fs.File = function (options) { }, write: function (data, position) { + //node.debug("internal write"); var promise = node.fs.write(self.fd, data, position); promise.addCallback(success); promise.addErrback(error); @@ -186,6 +179,7 @@ node.fs.File = function (options) { }; self.write = function (buf, pos) { + //node.debug("external write"); return createAction("write", [buf, pos]); }; @@ -204,4 +198,7 @@ stdin = new node.fs.File({ fd: node.STDIN_FILENO }); puts = stdout.puts; print = stdout.print; -p = function (data) { return puts(JSON.stringify(data)); } +p = function (data) { + return puts(JSON.stringify(data)); +} + -- 2.7.4