Skip to content

Commit 329fc78

Browse files
committed
fs: add initial set of fs.promises APIs
Initial set of fs.promises APIs with documentation and one benchmark. PR-URL: #18297 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 85b37db commit 329fc78

10 files changed

+1957
-187
lines changed

benchmark/fs/bench-stat-promise.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const fs = require('fs');
5+
6+
const bench = common.createBenchmark(main, {
7+
n: [20e4],
8+
statType: ['fstat', 'lstat', 'stat']
9+
});
10+
11+
async function run(n, statType) {
12+
const arg = statType === 'fstat' ?
13+
await fs.promises.open(__filename, 'r') : __filename;
14+
let remaining = n;
15+
bench.start();
16+
while (remaining-- > 0)
17+
await fs.promises[statType](arg);
18+
bench.end(n);
19+
20+
if (typeof arg.close === 'function')
21+
await arg.close();
22+
}
23+
24+
function main(conf) {
25+
const n = conf.n >>> 0;
26+
const statType = conf.statType;
27+
run(n, statType).catch(console.log);
28+
}

0 commit comments

Comments
 (0)