@@ -11,11 +11,14 @@ public static class PredictionResponseExtensions
1111 /// <param name="response"></param>
1212 /// <returns></returns>
1313 /// <exception cref="ArgumentNullException"></exception>
14- public static bool IsSuccessful ( this PredictionResponse response )
14+ public static bool IsCompleted ( this SchemasPredictionResponse response )
1515 {
1616 response = response ?? throw new ArgumentNullException ( nameof ( response ) ) ;
1717
18- return response . Status == "succeeded" ;
18+ return response . Status is
19+ SchemasPredictionResponseStatus . Succeeded or
20+ SchemasPredictionResponseStatus . Canceled or
21+ SchemasPredictionResponseStatus . Failed ;
1922 }
2023
2124 /// <summary>
@@ -27,22 +30,23 @@ public static bool IsSuccessful(this PredictionResponse response)
2730 /// <returns></returns>
2831 /// <exception cref="ArgumentNullException"></exception>
2932 /// <exception cref="ArgumentException"></exception>
30- public static async Task < PredictionResponse > WaitUntilSuccessfulAsync (
31- this PredictionResponse response ,
33+ public static async Task < PredictionResponse ? > WaitUntilSuccessfulAsync (
34+ this SchemasPredictionResponse response ,
3235 ReplicateApi api ,
3336 CancellationToken cancellationToken = default )
3437 {
3538 response = response ?? throw new ArgumentNullException ( nameof ( response ) ) ;
3639 api = api ?? throw new ArgumentNullException ( nameof ( api ) ) ;
3740 var id = response . Id ?? throw new ArgumentException ( nameof ( response . Id ) ) ;
3841
39- while ( ! response . IsSuccessful ( ) )
42+ PredictionResponse ? predictionResponse = null ;
43+ while ( ! response . IsCompleted ( ) )
4044 {
4145 await Task . Delay ( 1000 , cancellationToken ) . ConfigureAwait ( false ) ;
4246
43- response = await api . PredictionsGetAsync ( id , cancellationToken ) . ConfigureAwait ( false ) ;
47+ predictionResponse = await api . PredictionsGetAsync ( id , cancellationToken ) . ConfigureAwait ( false ) ;
4448 }
4549
46- return response ;
50+ return predictionResponse ;
4751 }
4852}
0 commit comments