@@ -8,26 +8,22 @@ if (process.argv[2] !== 'child') {
8
8
console . error ( '[%d] master' , process . pid ) ;
9
9
10
10
const worker = fork ( __filename , [ 'child' ] ) ;
11
- let called = false ;
11
+ let result = '' ;
12
12
13
- worker . once ( 'message' , common . mustCall ( function ( msg , handle ) {
13
+ worker . once ( 'message' , common . mustCall ( ( msg , handle ) => {
14
14
assert . strictEqual ( msg , 'handle' ) ;
15
15
assert . ok ( handle ) ;
16
16
worker . send ( 'got' ) ;
17
17
18
- handle . on ( 'data' , function ( data ) {
19
- called = true ;
20
- assert . strictEqual ( data . toString ( ) , 'hello' ) ;
18
+ handle . on ( 'data' , ( data ) => {
19
+ result += data . toString ( ) ;
21
20
} ) ;
22
21
23
- handle . on ( 'end' , function ( ) {
22
+ handle . on ( 'end' , ( ) => {
23
+ assert . strictEqual ( result , 'hello' ) ;
24
24
worker . kill ( ) ;
25
25
} ) ;
26
26
} ) ) ;
27
-
28
- process . once ( 'exit' , function ( ) {
29
- assert . ok ( called ) ;
30
- } ) ;
31
27
} else {
32
28
console . error ( '[%d] worker' , process . pid ) ;
33
29
@@ -38,20 +34,20 @@ if (process.argv[2] !== 'child') {
38
34
process . send ( 'handle' , socket ) ;
39
35
}
40
36
41
- const server = net . createServer ( function ( c ) {
42
- process . once ( 'message' , common . mustCall ( function ( msg ) {
37
+ const server = net . createServer ( ( c ) => {
38
+ process . once ( 'message' , common . mustCall ( ( msg ) => {
43
39
assert . strictEqual ( msg , 'got' ) ;
44
40
c . end ( 'hello' ) ;
45
41
} ) ) ;
46
42
socketConnected ( ) ;
47
43
} ) ;
48
44
49
- server . listen ( common . PORT , function ( ) {
50
- socket = net . connect ( common . PORT , '127.0.0.1' , socketConnected ) ;
45
+ server . listen ( common . PORT , ( ) => {
46
+ socket = net . connect ( server . address ( ) . port , server . address ( ) . address ,
47
+ socketConnected ) ;
51
48
} ) ;
52
49
53
- process . on ( 'disconnect' , function ( ) {
54
- process . exit ( ) ;
50
+ process . on ( 'disconnect' , ( ) => {
55
51
server . close ( ) ;
56
52
} ) ;
57
53
}
0 commit comments