@@ -27,7 +27,7 @@ t.test('two by two', t => {
2727 calledTre = true
2828 res ( 3 )
2929 } , 50 ) ) ,
30- ] , 2 ) . then ( res => t . strictSame ( res , [ 1 , 2 , 3 ] ) )
30+ ] , { limit : 2 } ) . then ( res => t . strictSame ( res , [ 1 , 2 , 3 ] ) )
3131} )
3232
3333t . test ( 'rejection' , t => t . rejects ( callLimit ( [
@@ -39,3 +39,28 @@ t.test('triple rejection', t => t.rejects(callLimit([
3939 ( ) => Promise . reject ( new Error ( 'poop' ) ) ,
4040 ( ) => Promise . reject ( new Error ( 'poop' ) ) ,
4141] ) , { message : 'poop' } ) )
42+
43+ t . test ( 'late rejection' , async t => {
44+ const results = [ ]
45+ await t . rejects ( callLimit ( [
46+ ( ) => new Promise ( resolve => setTimeout ( ( ) => {
47+ results . push ( 'first success' )
48+ resolve ( 'ok' )
49+ } , 50 ) ) ,
50+ ( ) => new Promise ( ( _ , reject ) => {
51+ setTimeout ( ( ) => {
52+ results . push ( 'slow rejection' )
53+ reject ( new Error ( 'slow rejection' ) )
54+ } , 100 )
55+ } ) ,
56+ ( ) => {
57+ results . push ( 'fast rejection' )
58+ return Promise . reject ( new Error ( 'fast rejection' ) )
59+ } ,
60+ ( ) => new Promise ( resolve => setTimeout ( ( ) => {
61+ results . push ( 'second success' )
62+ resolve ( 'ok 2' )
63+ } , 50 ) ) ,
64+ ] , { limit : 2 , rejectLate : true } ) , { message : 'fast rejection' } )
65+ t . match ( results , [ 'first success' , 'fast rejection' , 'slow rejection' , 'second success' ] )
66+ } )
0 commit comments