我终于得出结论,目前不可能。
为了防止大规模泛滥,我使用了模块的queue
对象。async
代码是这样的:
var queue = new Sync.Queue( function ( task, markAsComplete ) {
Http.request( {
agent : false, // we will use our own rate limiter, so we don't need agents
...
}, function ( err, res ) {
res.on( 'end', function ( ) {
if ( IS_503 ) {
var originalConcurrency = queue.concurrency; // saving the original concurrency
queue.concurrency = 1; // our timeout will now stop every request
setTimeout( function ( ) {
queue.concurrency = originalConcurrency; // restoring the concurrency
queue.push( task );
markAsComplete( );
}, 1000 );
}
} );
} );
}, numberOfParallelRequests );