Created
July 22, 2021 18:35
-
-
Save isaacs/9227f61bbdad7bf245a5b585c42621bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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