2023-06-25 14:18:54 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2025-05-11 16:53:21 +02:00
|
|
|
const assert = require('assert');
|
|
|
|
const { opendirSync, promises: fs } = require('fs');
|
2023-06-25 14:18:54 +03:00
|
|
|
|
2025-05-11 16:53:21 +02:00
|
|
|
async function explicitCall() {
|
2023-06-25 14:18:54 +03:00
|
|
|
const fh = await fs.open(__filename);
|
|
|
|
fh.on('close', common.mustCall());
|
|
|
|
await fh[Symbol.asyncDispose]();
|
2025-05-11 16:53:21 +02:00
|
|
|
|
|
|
|
const dh = await fs.opendir(__dirname);
|
|
|
|
await dh[Symbol.asyncDispose]();
|
|
|
|
await assert.rejects(dh.read(), { code: 'ERR_DIR_CLOSED' });
|
|
|
|
|
|
|
|
const dhSync = opendirSync(__dirname);
|
|
|
|
dhSync[Symbol.dispose]();
|
|
|
|
assert.throws(() => dhSync.readSync(), { code: 'ERR_DIR_CLOSED' });
|
2023-06-25 14:18:54 +03:00
|
|
|
}
|
|
|
|
|
2025-05-11 16:53:21 +02:00
|
|
|
explicitCall().then(common.mustCall());
|
|
|
|
// TODO(aduh95): add test for implicit calls, with `await using` syntax.
|