|
1 | 1 | 'use strict'; |
2 | | -varcommon=require('../common'); |
3 | | -varassert=require('assert'); |
| 2 | +constcommon=require('../common'); |
| 3 | +constassert=require('assert'); |
4 | 4 |
|
5 | 5 | // Make sure that throwing in 'end' handler doesn't lock |
6 | 6 | // up the socket forever. |
7 | 7 | // |
8 | 8 | // This is NOT a good way to handle errors in general, but all |
9 | 9 | // the same, we should not be so brittle and easily broken. |
10 | 10 |
|
11 | | -varhttp=require('http'); |
| 11 | +consthttp=require('http'); |
12 | 12 |
|
13 | | -varn=0; |
14 | | -varserver=http.createServer(function(req,res){ |
| 13 | +letn=0; |
| 14 | +constserver=http.createServer((req,res)=>{ |
15 | 15 | if(++n===10)server.close(); |
16 | 16 | res.end('ok'); |
17 | 17 | }); |
18 | 18 |
|
19 | | -server.listen(common.PORT,function(){ |
20 | | -for(vari=0;i<10;i++){ |
21 | | -varoptions={port: common.PORT}; |
22 | | - |
23 | | -varreq=http.request(options,function(res){ |
| 19 | +server.listen(common.PORT,common.mustCall(()=>{ |
| 20 | +for(leti=0;i<10;i++){ |
| 21 | +constoptions={port: common.PORT}; |
| 22 | +constreq=http.request(options,(res)=>{ |
24 | 23 | res.resume(); |
25 | | -res.on('end',function(){ |
| 24 | +res.on('end',common.mustCall(()=>{ |
26 | 25 | thrownewError('gleep glorp'); |
27 | | -}); |
| 26 | +})); |
28 | 27 | }); |
29 | 28 | req.end(); |
30 | 29 | } |
31 | | -}); |
| 30 | +})); |
32 | 31 |
|
33 | | -setTimeout(function(){ |
34 | | -process.removeListener('uncaughtException',catcher); |
35 | | -thrownewError('Taking too long!'); |
36 | | -},common.platformTimeout(1000)).unref(); |
37 | | - |
38 | | -process.on('uncaughtException',catcher); |
39 | | -varerrors=0; |
40 | | -functioncatcher(){ |
| 32 | +leterrors=0; |
| 33 | +process.on('uncaughtException',()=>{ |
41 | 34 | errors++; |
42 | | -} |
| 35 | +}); |
43 | 36 |
|
44 | | -process.on('exit',function(){ |
| 37 | +process.on('exit',()=>{ |
45 | 38 | assert.equal(errors,10); |
46 | | -console.log('ok'); |
47 | 39 | }); |
0 commit comments