@@ -35,30 +35,25 @@ fs.open(filepath, 'r', common.mustSucceed((fd) => {
35
35
} ) ) ;
36
36
} ) ) ;
37
37
38
- let filehandle = null ;
39
-
40
38
// Tests for promises api
41
39
( async ( ) => {
42
- filehandle = await fsPromises . open ( filepath , 'r' ) ;
40
+ await using filehandle = await fsPromises . open ( filepath , 'r' ) ;
43
41
const readObject = await filehandle . read ( buf , { offset : null } ) ;
44
42
assert . strictEqual ( readObject . buffer [ 0 ] , 120 ) ;
45
43
} ) ( )
46
- . finally ( ( ) => filehandle ?. close ( ) )
47
44
. then ( common . mustCall ( ) ) ;
48
45
49
46
// Undocumented: omitted position works the same as position === null
50
47
( async ( ) => {
51
- filehandle = await fsPromises . open ( filepath , 'r' ) ;
48
+ await using filehandle = await fsPromises . open ( filepath , 'r' ) ;
52
49
const readObject = await filehandle . read ( buf , null , buf . length ) ;
53
50
assert . strictEqual ( readObject . buffer [ 0 ] , 120 ) ;
54
51
} ) ( )
55
- . finally ( ( ) => filehandle ?. close ( ) )
56
52
. then ( common . mustCall ( ) ) ;
57
53
58
54
( async ( ) => {
59
- filehandle = await fsPromises . open ( filepath , 'r' ) ;
55
+ await using filehandle = await fsPromises . open ( filepath , 'r' ) ;
60
56
const readObject = await filehandle . read ( buf , null , buf . length , 0 ) ;
61
57
assert . strictEqual ( readObject . buffer [ 0 ] , 120 ) ;
62
58
} ) ( )
63
- . finally ( ( ) => filehandle ?. close ( ) )
64
59
. then ( common . mustCall ( ) ) ;
0 commit comments