Created
September 17, 2020 12:19
-
-
Save EngRajabi/ec04cf7f95dac84b030d7f87e716f4e6 to your computer and use it in GitHub Desktop.
Workers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add to di singleton | |
public class Workers | |
{ | |
private ConcurrentBag<IDataflowBlock> Actions { get; set; } = new ConcurrentBag<IDataflowBlock>(); | |
public ActionBlock<TInput> AddWork<TInput>(Func<TInput, Task> work) where TInput : class, new() | |
{ | |
var action = new ActionBlock<TInput>(work); | |
Actions.Add(action); | |
return action; | |
} | |
public ActionBlock<TInput> AddWork<TInput>(Action<TInput> work) where TInput : class, new() | |
{ | |
var action = new ActionBlock<TInput>(work); | |
Actions.Add(action); | |
return action; | |
} | |
public ActionBlock<TInput> AddWork<TInput>(Func<TInput, Task> work, ExecutionDataflowBlockOptions dataflowBlockOptions) where TInput : class, new() | |
{ | |
var action = new ActionBlock<TInput>(work, dataflowBlockOptions); | |
Actions.Add(action); | |
return action; | |
} | |
public ActionBlock<TInput> AddWork<TInput>(Action<TInput> work, ExecutionDataflowBlockOptions dataflowBlockOptions) where TInput : class, new() | |
{ | |
var action = new ActionBlock<TInput>(work, dataflowBlockOptions); | |
Actions.Add(action); | |
return action; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment