1
- using System ;
1
+ using System ;
2
+ using System . Collections . Concurrent ;
2
3
using System . Collections . Generic ;
3
4
using System . Linq ;
4
5
using Microsoft . Extensions . DependencyInjection ;
@@ -10,7 +11,7 @@ namespace WorkflowCore.Services
10
11
public class WorkflowRegistry : IWorkflowRegistry
11
12
{
12
13
private readonly IServiceProvider _serviceProvider ;
13
- private readonly List < Tuple < string , int , WorkflowDefinition > > _registry = new List < Tuple < string , int , WorkflowDefinition > > ( ) ;
14
+ private readonly BlockingCollection < Tuple < string , int , WorkflowDefinition > > _registry = new BlockingCollection < Tuple < string , int , WorkflowDefinition > > ( ) ;
14
15
15
16
public WorkflowRegistry ( IServiceProvider serviceProvider )
16
17
{
@@ -35,10 +36,10 @@ public WorkflowDefinition GetDefinition(string workflowId, int? version = null)
35
36
36
37
public void DeregisterWorkflow ( string workflowId , int version )
37
38
{
38
- var definition = _registry . Find ( x => x . Item1 == workflowId && x . Item2 == version ) ;
39
+ var definition = _registry . FirstOrDefault ( x => x . Item1 == workflowId && x . Item2 == version ) ;
39
40
if ( definition != null )
40
41
{
41
- _registry . Remove ( definition ) ;
42
+ _registry . TryTake ( out definition ) ;
42
43
}
43
44
}
44
45
@@ -81,7 +82,7 @@ public void RegisterWorkflow<TData>(IWorkflow<TData> workflow)
81
82
82
83
public bool IsRegistered ( string workflowId , int version )
83
84
{
84
- var definition = _registry . Find ( x => x . Item1 == workflowId && x . Item2 == version ) ;
85
+ var definition = _registry . FirstOrDefault ( x => x . Item1 == workflowId && x . Item2 == version ) ;
85
86
return ( definition != null ) ;
86
87
}
87
88
0 commit comments