File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed
projects/RabbitMQ.Client/client/impl Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -9,13 +9,20 @@ namespace RabbitMQ.Client.Impl
9
9
internal sealed class AsyncConsumerWorkService : ConsumerWorkService
10
10
{
11
11
private readonly ConcurrentDictionary < IModel , WorkPool > _workPools = new ConcurrentDictionary < IModel , WorkPool > ( ) ;
12
+ private readonly Func < IModel , WorkPool > _startNewWorkPoolFunc = model => StartNewWorkPool ( model ) ;
12
13
13
14
public void Schedule < TWork > ( ModelBase model , TWork work ) where TWork : Work
14
15
{
15
- _workPools . GetOrAdd ( model , StartNewWorkPool ) . Enqueue ( work ) ;
16
+ /*
17
+ * rabbitmq/rabbitmq-dotnet-client#841
18
+ * https://docs.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentdictionary-2.getoradd
19
+ * Note that the value delegate is not atomic but the Schedule method will not be called concurrently.
20
+ */
21
+ WorkPool workPool = _workPools . GetOrAdd ( model , _startNewWorkPoolFunc ) ;
22
+ workPool . Enqueue ( work ) ;
16
23
}
17
24
18
- private WorkPool StartNewWorkPool ( IModel model )
25
+ private static WorkPool StartNewWorkPool ( IModel model )
19
26
{
20
27
var newWorkPool = new WorkPool ( model as ModelBase ) ;
21
28
newWorkPool . Start ( ) ;
Original file line number Diff line number Diff line change 5
5
6
6
namespace RabbitMQ . Client . Impl
7
7
{
8
- class ConsumerWorkService
8
+ internal class ConsumerWorkService
9
9
{
10
10
private readonly ConcurrentDictionary < IModel , WorkPool > _workPools = new ConcurrentDictionary < IModel , WorkPool > ( ) ;
11
+ private readonly Func < IModel , WorkPool > _startNewWorkPoolFunc = model => StartNewWorkPool ( model ) ;
11
12
12
13
public void AddWork ( IModel model , Action fn )
13
14
{
14
- _workPools . GetOrAdd ( model , StartNewWorkPool ) . Enqueue ( fn ) ;
15
+ /*
16
+ * rabbitmq/rabbitmq-dotnet-client#841
17
+ * https://docs.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentdictionary-2.getoradd
18
+ * Note that the value delegate is not atomic but the AddWork method will not be called concurrently.
19
+ */
20
+ WorkPool workPool = _workPools . GetOrAdd ( model , _startNewWorkPoolFunc ) ;
21
+ workPool . Enqueue ( fn ) ;
15
22
}
16
23
17
- private WorkPool StartNewWorkPool ( IModel model )
24
+ private static WorkPool StartNewWorkPool ( IModel model )
18
25
{
19
26
var newWorkPool = new WorkPool ( ) ;
20
27
newWorkPool . Start ( ) ;
You can’t perform that action at this time.
0 commit comments