Skip to content

Commit e11f696

Browse files
authored
Update WorkflowRegistry.cs
Changed registry collection to a thread safe collection.
1 parent 906a7d7 commit e11f696

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/WorkflowCore/Services/WorkflowRegistry.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using System;
2+
using System.Collections.Concurrent;
23
using System.Collections.Generic;
34
using System.Linq;
45
using Microsoft.Extensions.DependencyInjection;
@@ -10,7 +11,7 @@ namespace WorkflowCore.Services
1011
public class WorkflowRegistry : IWorkflowRegistry
1112
{
1213
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>>();
1415

1516
public WorkflowRegistry(IServiceProvider serviceProvider)
1617
{
@@ -35,10 +36,10 @@ public WorkflowDefinition GetDefinition(string workflowId, int? version = null)
3536

3637
public void DeregisterWorkflow(string workflowId, int version)
3738
{
38-
var definition = _registry.Find(x => x.Item1 == workflowId && x.Item2 == version);
39+
var definition = _registry.FirstOrDefault(x => x.Item1 == workflowId && x.Item2 == version);
3940
if (definition != null)
4041
{
41-
_registry.Remove(definition);
42+
_registry.TryTake(out definition);
4243
}
4344
}
4445

@@ -81,7 +82,7 @@ public void RegisterWorkflow<TData>(IWorkflow<TData> workflow)
8182

8283
public bool IsRegistered(string workflowId, int version)
8384
{
84-
var definition = _registry.Find(x => x.Item1 == workflowId && x.Item2 == version);
85+
var definition = _registry.FirstOrDefault(x => x.Item1 == workflowId && x.Item2 == version);
8586
return (definition != null);
8687
}
8788

0 commit comments

Comments
 (0)