File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed
tests/Temporalio.Tests/Client Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -458,6 +458,7 @@ private async IAsyncEnumerable<WorkflowExecution> ListWorkflowsInternalAsync(
458
458
// Need to combine cancellation token
459
459
var rpcOptsAndCancelSource = DefaultRetryOptions ( input . Options ? . Rpc ) .
460
460
WithAdditionalCancellationToken ( cancellationToken ) ;
461
+ var yielded = 0 ;
461
462
try
462
463
{
463
464
var req = new ListWorkflowExecutionsRequest ( )
@@ -472,6 +473,11 @@ private async IAsyncEnumerable<WorkflowExecution> ListWorkflowsInternalAsync(
472
473
req , rpcOptsAndCancelSource . Item1 ) . ConfigureAwait ( false ) ;
473
474
foreach ( var exec in resp . Executions )
474
475
{
476
+ if ( input . Options != null && input . Options . Limit > 0 &&
477
+ yielded ++ >= input . Options . Limit )
478
+ {
479
+ yield break ;
480
+ }
475
481
yield return new ( exec , Client . Options . DataConverter ) ;
476
482
}
477
483
req . NextPageToken = resp . NextPageToken ;
Original file line number Diff line number Diff line change @@ -13,6 +13,11 @@ public class WorkflowListOptions : ICloneable
13
13
/// </summary>
14
14
public RpcOptions ? Rpc { get ; set ; }
15
15
16
+ /// <summary>
17
+ /// Gets or sets the maximum number of workflows to return. A zero value means no limit.
18
+ /// </summary>
19
+ public int Limit { get ; set ; }
20
+
16
21
/// <summary>
17
22
/// Create a shallow copy of these options.
18
23
/// </summary>
@@ -28,4 +33,4 @@ public virtual object Clone()
28
33
}
29
34
}
30
35
}
31
- #endif
36
+ #endif
Original file line number Diff line number Diff line change @@ -272,6 +272,15 @@ await Client.ExecuteWorkflowAsync(
272
272
actualResults . Add ( result ) ;
273
273
}
274
274
Assert . Equal ( expectedResults , actualResults ) ;
275
+
276
+ // Verify limit option works
277
+ var limitedResults = 0 ;
278
+ await foreach ( var wf in Client . ListWorkflowsAsync (
279
+ $ "WorkflowId = '{ workflowId } '", new ( ) { Limit = 3 } ) )
280
+ {
281
+ limitedResults ++ ;
282
+ }
283
+ Assert . Equal ( 3 , limitedResults ) ;
275
284
}
276
285
277
286
[ Workflow ]
You can’t perform that action at this time.
0 commit comments