@@ -140,6 +140,26 @@ public void IgnoreExceptionTypes(params Type[] exceptionTypes)
140140 /// <param name="condition">A delegate taking an object of type T as its parameter, and returning a TResult.</param>
141141 /// <returns>The delegate's return value.</returns>
142142 public virtual TResult Until < TResult > ( Func < T , TResult > condition )
143+ {
144+ return Until ( condition , CancellationToken . None ) ;
145+ }
146+
147+ /// <summary>
148+ /// Repeatedly applies this instance's input value to the given function until one of the following
149+ /// occurs:
150+ /// <para>
151+ /// <list type="bullet">
152+ /// <item>the function returns neither null nor false</item>
153+ /// <item>the function throws an exception that is not in the list of ignored exception types</item>
154+ /// <item>the timeout expires</item>
155+ /// </list>
156+ /// </para>
157+ /// </summary>
158+ /// <typeparam name="TResult">The delegate's expected return type.</typeparam>
159+ /// <param name="condition">A delegate taking an object of type T as its parameter, and returning a TResult.</param>
160+ /// <param name="token">A cancellation token that can be used to cancel the wait.</param>
161+ /// <returns>The delegate's return value.</returns>
162+ public virtual TResult Until < TResult > ( Func < T , TResult > condition , CancellationToken token )
143163 {
144164 if ( condition == null )
145165 {
@@ -156,6 +176,8 @@ public virtual TResult Until<TResult>(Func<T, TResult> condition)
156176 var endTime = this . clock . LaterBy ( this . timeout ) ;
157177 while ( true )
158178 {
179+ token . ThrowIfCancellationRequested ( ) ;
180+
159181 try
160182 {
161183 var result = condition ( this . input ) ;
0 commit comments