Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created July 22, 2021 18:35
Show Gist options
  • Save isaacs/9227f61bbdad7bf245a5b585c42621bf to your computer and use it in GitHub Desktop.
Save isaacs/9227f61bbdad7bf245a5b585c42621bf to your computer and use it in GitHub Desktop.
const fs = require('fs')
const gfs = require('./')
const filename = 'foo'
console.log('starting')
// fill up the set of available file descriptors
const fds = []
while (true) {
try {
fds.push(fs.openSync(filename, 'w'))
} catch (er) {
if (er.code !== 'ENFILE' && er.code !== 'EMFILE')
throw er
break
}
}
// now we're fully booked. kick off a gfs open.
gfs.open(filename, 'w', (er, fd) => {
if (er)
throw er
console.log('got graceful fd', fd)
})
const int = setInterval(() => {
fs.closeSync(fds.shift())
if (!fds.length)
clearInterval(int)
}, 100)
int.unref()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment