@@ -32,7 +32,15 @@ public SyncWorkflowRunner(IWorkflowHost host, IWorkflowExecutor executor, IDistr
3232 _dateTimeProvider = dateTimeProvider ;
3333 }
3434
35- public async Task < WorkflowInstance > RunWorkflowSync < TData > ( string workflowId , int version , TData data , string reference , TimeSpan timeOut , bool persistSate = true )
35+ public Task < WorkflowInstance > RunWorkflowSync < TData > ( string workflowId , int version , TData data ,
36+ string reference , TimeSpan timeOut , bool persistSate = true )
37+ where TData : new ( )
38+ {
39+ return RunWorkflowSync ( workflowId , version , data , reference , new CancellationTokenSource ( timeOut ) . Token ,
40+ persistSate ) ;
41+ }
42+
43+ public async Task < WorkflowInstance > RunWorkflowSync < TData > ( string workflowId , int version , TData data , string reference , CancellationToken token , bool persistSate = true )
3644 where TData : new ( )
3745 {
3846 var def = _registry . GetDefinition ( workflowId , version ) ;
@@ -63,8 +71,6 @@ public async Task<WorkflowInstance> RunWorkflowSync<TData>(string workflowId, in
6371
6472 wf . ExecutionPointers . Add ( _pointerFactory . BuildGenesisPointer ( def ) ) ;
6573
66- var stopWatch = new Stopwatch ( ) ;
67-
6874 var id = Guid . NewGuid ( ) . ToString ( ) ;
6975
7076 if ( persistSate )
@@ -81,8 +87,7 @@ public async Task<WorkflowInstance> RunWorkflowSync<TData>(string workflowId, in
8187
8288 try
8389 {
84- stopWatch . Start ( ) ;
85- while ( ( wf . Status == WorkflowStatus . Runnable ) && ( timeOut . TotalMilliseconds > stopWatch . ElapsedMilliseconds ) )
90+ while ( ( wf . Status == WorkflowStatus . Runnable ) && ! token . IsCancellationRequested )
8691 {
8792 await _executor . Execute ( wf ) ;
8893 if ( persistSate )
@@ -91,7 +96,6 @@ public async Task<WorkflowInstance> RunWorkflowSync<TData>(string workflowId, in
9196 }
9297 finally
9398 {
94- stopWatch . Stop ( ) ;
9599 await _lockService . ReleaseLock ( id ) ;
96100 }
97101
0 commit comments