Skip to content

Commit

Permalink
Add Node.js 0.x polyfill for global retry queue name
Browse files Browse the repository at this point in the history
Symbol.for was not added until Node.js v4.

Graceful-fs version 5 will drop support for Node.js <8, so we can also
back out this polyfill at that time.
  • Loading branch information
isaacs committed Aug 14, 2019
1 parent 20b77c4 commit 770ee51
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions graceful-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ var clone = require('./clone.js')

var util = require('util')

var gracefulQueue = Symbol.for('graceful-fs.queue')
/* istanbul ignore next - node 0.x polyfill */
var gracefulQueue
var previousSymbol

/* istanbul ignore else - node 0.x polyfill */
if (typeof Symbol === 'function' && typeof Symbol.for === 'function') {
gracefulQueue = Symbol.for('graceful-fs.queue')
// This is used in testing by future versions
previousSymbol = Symbol.for('graceful-fs.previous')
} else {
gracefulQueue = '___graceful-fs.queue'
previousSymbol = '___graceful-fs.previous'
}

function noop () {}

Expand All @@ -29,9 +41,6 @@ if (!global[gracefulQueue]) {
}
})

// This is used in testing by future versions
var previous = Symbol.for('graceful-fs.previous')

// Patch fs.close/closeSync to shared queue version, because we need
// to retry() whenever a close happens *anywhere* in the program.
// This is essential when multiple graceful-fs instances are
Expand All @@ -49,7 +58,7 @@ if (!global[gracefulQueue]) {
})
}

close[previous] = fs$close
close[previousSymbol] = fs$close
return close
})(fs.close)

Expand All @@ -60,7 +69,7 @@ if (!global[gracefulQueue]) {
retry()
}

closeSync[previous] = fs$closeSync
closeSync[previousSymbol] = fs$closeSync
return closeSync
})(fs.closeSync)

Expand Down

0 comments on commit 770ee51

Please sign in to comment.