From 49de57ae8a93bdfcb64050b3508a660fc6f55cbc Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Thu, 10 Jan 2013 11:39:05 +1100 Subject: [PATCH] switch from _usingfd to _fds, purely aesthetic --- index.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 764f06a..9783a4d 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const fs = require('fs') var totalOpenFds = 0 // across all instances // the reason we use a combination of path+fd to store references - // in this._usingfd is that it is possible to have multiple fds + // in this._fds is that it is possible to have multiple fds // for the same file simultaneously. Particularly in the situation // where an fd is pending for a close but hasn't been checked back // in by all clients @@ -14,8 +14,8 @@ var totalOpenFds = 0 // across all instances , cleanupFd = function (path, fd) { // clear the use counter & close if pending - delete this._usingfd[key(path, fd)] - delete this._usingfd[path] + delete this._fds[key(path, fd)] + delete this._fds[path] if (this._pendingClose[key(path, fd)]) { console.log('close', path, fd) @@ -32,7 +32,7 @@ var totalOpenFds = 0 // across all instances // nextTick needed to match the nextTick in an async-cache otherwise we may // close it in the tick prior to it being actually needed process.nextTick(function () { - if (!this._usingfd[key(path, fd)]) + if (!this._fds[key(path, fd)]) cleanupFd.call(this, path, fd) }.bind(this)) } @@ -42,15 +42,15 @@ var totalOpenFds = 0 // across all instances // if the file is already open and in use but not with a close pending // then just use that. - if (this._usingfd[path] && !this._pendingClose[key(path, this._usingfd[path])]) - return cb(null, this._usingfd[path]) + if (this._fds[path] && !this._pendingClose[key(path, this._fds[path])]) + return cb(null, this._fds[path]) fs.open(path, 'r', function (er, fd) { if (!er) { console.log('open', path, fd) totalOpenFds++ - this._usingfd[path] = fd - this._usingfd[fd + path] = 0 + this._fds[path] = fd + this._fds[fd + path] = 0 } cb(er, fd) @@ -60,14 +60,14 @@ var totalOpenFds = 0 // across all instances , checkout = function (path, fd) { // call whenever you *may* be about to use the fd, to ensure it's not cleaned up - this._usingfd[path] = fd - this._usingfd[key(path, fd)] = (this._usingfd[key(path, fd)] || 0) + 1 + this._fds[path] = fd + this._fds[key(path, fd)] = (this._fds[key(path, fd)] || 0) + 1 } , checkin = function (path, fd) { // call sometime after checkout() when you know you're not using it - if (this._usingfd[path] && --this._usingfd[key(path, fd)] === 0) + if (this._fds[path] && --this._fds[key(path, fd)] === 0) cleanupFd.call(this, path, fd) } @@ -93,7 +93,7 @@ var totalOpenFds = 0 // across all instances , create = function () { return Object.create(FDManager, { - _usingfd : { value: Object.create(null) } + _fds : { value: Object.create(null) } , _pendingClose : { value: Object.create(null) } }) }