|
|
@ -1,3 +1,6 @@ |
|
|
|
/*jslint onevar: true, undef: true, eqeqeq: true, plusplus: true, regexp: true, newcap: true, immed: true */ |
|
|
|
/*globals exports, node, __filename */ |
|
|
|
|
|
|
|
exports.debugLevel = 0; // Increase to get more verbose debug output
|
|
|
|
|
|
|
|
function debugMessage (msg) { |
|
|
@ -27,7 +30,7 @@ exports.write = function (filename, data, encoding) { |
|
|
|
node.fs.close(fd); |
|
|
|
}) |
|
|
|
.addCallback(function (written) { |
|
|
|
if (written == _data.length) { |
|
|
|
if (written === _data.length) { |
|
|
|
node.fs.close(fd); |
|
|
|
} else { |
|
|
|
doWrite(_data.slice(written)); |
|
|
@ -37,7 +40,7 @@ exports.write = function (filename, data, encoding) { |
|
|
|
doWrite(data); |
|
|
|
}) |
|
|
|
.addErrback(function () { |
|
|
|
promise.emitError() |
|
|
|
promise.emitError(); |
|
|
|
}); |
|
|
|
|
|
|
|
return promise; |
|
|
@ -94,38 +97,40 @@ exports.File = function (filename, mode, options) { |
|
|
|
var proto = exports.File.prototype; |
|
|
|
|
|
|
|
proto._maybeDispatch = function () { |
|
|
|
var self = this; |
|
|
|
var self, args, method, promise, userPromise; |
|
|
|
|
|
|
|
self = this; |
|
|
|
|
|
|
|
if (self.currentAction) return; |
|
|
|
if (self.currentAction) { return; } |
|
|
|
self.currentAction = self.actionQueue.shift(); |
|
|
|
if (!self.currentAction) return; |
|
|
|
if (!self.currentAction) { return; } |
|
|
|
|
|
|
|
debugObject(self.currentAction); |
|
|
|
|
|
|
|
var args = self.currentAction.args || []; |
|
|
|
args = self.currentAction.args || []; |
|
|
|
|
|
|
|
if (self.currentAction.method != "open") { |
|
|
|
if (self.currentAction.method !== "open") { |
|
|
|
args.unshift(self.fd); |
|
|
|
} |
|
|
|
|
|
|
|
var method = self.currentAction.method; |
|
|
|
method = self.currentAction.method; |
|
|
|
|
|
|
|
if (!args[3] && (method == "read" || method == "write")) { |
|
|
|
if (!args[3] && (method === "read" || method === "write")) { |
|
|
|
args[3] = self.encoding; |
|
|
|
} |
|
|
|
|
|
|
|
var promise = node.fs[method].apply(self, args); |
|
|
|
promise = node.fs[method].apply(self, args); |
|
|
|
|
|
|
|
var userPromise = self.currentAction.promise; |
|
|
|
userPromise = self.currentAction.promise; |
|
|
|
|
|
|
|
promise.addCallback(function () { |
|
|
|
node.assert(self.currentAction.promise == userPromise); |
|
|
|
node.assert(self.currentAction.promise === userPromise); |
|
|
|
userPromise.emitSuccess.apply(userPromise, arguments); |
|
|
|
self.currentAction = null; |
|
|
|
self._maybeDispatch(); |
|
|
|
}).addErrback(function () { |
|
|
|
debugMessage("Error in method " + method); |
|
|
|
node.assert(self.currentAction.promise == userPromise); |
|
|
|
node.assert(self.currentAction.promise === userPromise); |
|
|
|
userPromise.emitError.apply(userPromise, arguments); |
|
|
|
self.currentAction = null; |
|
|
|
self._maybeDispatch(); |
|
|
@ -133,7 +138,7 @@ proto._maybeDispatch = function () { |
|
|
|
}; |
|
|
|
|
|
|
|
proto._queueAction = function (method, args) { |
|
|
|
var userPromise = new node.Promise; |
|
|
|
var userPromise = new node.Promise(); |
|
|
|
this.actionQueue.push({ method: method, args: args, promise: userPromise }); |
|
|
|
this._maybeDispatch(); |
|
|
|
return userPromise; |
|
|
|