@ -2,6 +2,7 @@
// but with an on('error') handler that does nothing.
// but with an on('error') handler that does nothing.
function serverHandler ( req , res ) {
function serverHandler ( req , res ) {
req . resume ( ) ;
res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
res . end ( 'Hello World\n' ) ;
res . end ( 'Hello World\n' ) ;
}
}
@ -23,28 +24,35 @@ var server = http.createServer(serverHandler);
server . listen ( PORT , getall ) ;
server . listen ( PORT , getall ) ;
function getall ( ) {
function getall ( ) {
for ( var i = 0 ; i < todo ; i ++ ) {
if ( count >= todo )
( function ( ) {
return ;
function cb ( res ) {
done += 1 ;
statusLater ( ) ;
}
function onerror ( er ) {
throw er ;
}
var req = http . get ( {
( function ( ) {
hostname : 'localhost' ,
function cb ( res ) {
pathname : '/' ,
res . resume ( ) ;
port : PORT
done += 1 ;
} , cb ) . on ( 'error' , onerror ) ;
statusLater ( ) ;
}
function onerror ( er ) {
throw er ;
}
count ++ ;
var req = http . get ( {
weak ( req , afterGC ) ;
hostname : 'localhost' ,
} ) ( )
pathname : '/' ,
}
port : PORT
} , cb ) . on ( 'error' , onerror ) ;
count ++ ;
weak ( req , afterGC ) ;
} ) ( )
setImmediate ( getall ) ;
}
}
for ( var i = 0 ; i < 10 ; i ++ )
getall ( ) ;
function afterGC ( ) {
function afterGC ( ) {
countGC ++ ;
countGC ++ ;
}
}
@ -62,7 +70,7 @@ function status() {
console . log ( 'Collected: %d/%d' , countGC , count ) ;
console . log ( 'Collected: %d/%d' , countGC , count ) ;
if ( done === todo ) {
if ( done === todo ) {
console . log ( 'All should be collected now.' ) ;
console . log ( 'All should be collected now.' ) ;
assert ( count === countGC ) ;
assert . strictEqual ( count , countGC ) ;
process . exit ( 0 ) ;
process . exit ( 0 ) ;
}
}
}
}