Skip to content

Commit

Permalink
switch from _usingfd to _fds, purely aesthetic
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jan 10, 2013
1 parent 49e9124 commit 49de57a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions index.js
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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))
}
Expand All @@ -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)
Expand All @@ -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)
}

Expand All @@ -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) }
})
}
Expand Down

0 comments on commit 49de57a

Please sign in to comment.