33
44using System ;
55using System . Net . Http ;
6+ using System . Threading ;
67using System . Threading . Tasks ;
78
89namespace JustEat . HttpClientInterception
@@ -25,14 +26,14 @@ internal static class DelegateHelpers
2526 /// <returns>
2627 /// The converted delegate if <paramref name="onIntercepted"/> has a value; otherwise <see langword="null"/>.
2728 /// </returns>
28- internal static Func < HttpRequestMessage , Task < bool > > ? ConvertToBooleanTask ( Action < HttpRequestMessage > ? onIntercepted )
29+ internal static Func < HttpRequestMessage , CancellationToken , Task < bool > > ? ConvertToBooleanTask ( Action < HttpRequestMessage > ? onIntercepted )
2930 {
3031 if ( onIntercepted == null )
3132 {
3233 return null ;
3334 }
3435
35- return ( message ) =>
36+ return ( message , _ ) =>
3637 {
3738 onIntercepted ( message ) ;
3839 return TrueTask ;
@@ -47,14 +48,14 @@ internal static class DelegateHelpers
4748 /// <returns>
4849 /// The converted delegate if <paramref name="onIntercepted"/> has a value; otherwise <see langword="null"/>.
4950 /// </returns>
50- internal static Func < HttpRequestMessage , Task < bool > > ? ConvertToBooleanTask ( Predicate < HttpRequestMessage > ? onIntercepted )
51+ internal static Func < HttpRequestMessage , CancellationToken , Task < bool > > ? ConvertToBooleanTask ( Predicate < HttpRequestMessage > ? onIntercepted )
5152 {
5253 if ( onIntercepted == null )
5354 {
5455 return null ;
5556 }
5657
57- return ( message ) => Task . FromResult ( onIntercepted ( message ) ) ;
58+ return ( message , _ ) => Task . FromResult ( onIntercepted ( message ) ) ;
5859 }
5960
6061 /// <summary>
@@ -65,18 +66,54 @@ internal static class DelegateHelpers
6566 /// <returns>
6667 /// The converted delegate if <paramref name="onIntercepted"/> has a value; otherwise <see langword="null"/>.
6768 /// </returns>
68- internal static Func < HttpRequestMessage , Task < bool > > ? ConvertToBooleanTask ( Func < HttpRequestMessage , Task > ? onIntercepted )
69+ internal static Func < HttpRequestMessage , CancellationToken , Task < bool > > ? ConvertToBooleanTask ( Func < HttpRequestMessage , Task > ? onIntercepted )
6970 {
7071 if ( onIntercepted == null )
7172 {
7273 return null ;
7374 }
7475
75- return async ( message ) =>
76+ return ConvertToBooleanTask ( ( message , _ ) => onIntercepted ( message ) ) ;
77+ }
78+
79+ /// <summary>
80+ /// Converts a function delegate for an intercepted message to return a
81+ /// <see cref="Task{TResult}"/> which returns <see langword="true"/>.
82+ /// </summary>
83+ /// <param name="onIntercepted">An optional delegate to convert.</param>
84+ /// <returns>
85+ /// The converted delegate if <paramref name="onIntercepted"/> has a value; otherwise <see langword="null"/>.
86+ /// </returns>
87+ internal static Func < HttpRequestMessage , CancellationToken , Task < bool > > ? ConvertToBooleanTask ( Func < HttpRequestMessage , CancellationToken , Task > ? onIntercepted )
88+ {
89+ if ( onIntercepted == null )
90+ {
91+ return null ;
92+ }
93+
94+ return async ( message , token ) =>
7695 {
77- await onIntercepted ( message ) . ConfigureAwait ( false ) ;
96+ await onIntercepted ( message , token ) . ConfigureAwait ( false ) ;
7897 return true ;
7998 } ;
8099 }
100+
101+ /// <summary>
102+ /// Converts a function delegate for an intercepted message to return a
103+ /// <see cref="Task{TResult}"/> which returns <see langword="true"/>.
104+ /// </summary>
105+ /// <param name="onIntercepted">An optional delegate to convert.</param>
106+ /// <returns>
107+ /// The converted delegate if <paramref name="onIntercepted"/> has a value; otherwise <see langword="null"/>.
108+ /// </returns>
109+ internal static Func < HttpRequestMessage , CancellationToken , Task < bool > > ? ConvertToBooleanTask ( Func < HttpRequestMessage , Task < bool > > ? onIntercepted )
110+ {
111+ if ( onIntercepted == null )
112+ {
113+ return null ;
114+ }
115+
116+ return async ( message , _ ) => await onIntercepted ( message ) . ConfigureAwait ( false ) ;
117+ }
81118 }
82119}
0 commit comments