Last active
May 25, 2020 17:47
-
-
Save mnadel/df2ec09fe7eae9ba8938 to your computer and use it in GitHub Desktop.
Revisions
-
mnadel revised this gist
Nov 8, 2015 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -22,9 +22,7 @@ class Pipeline<T> } }); _buffer.LinkTo(actionBlock); } void Post(T message) -
mnadel revised this gist
Nov 7, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ class Pipeline<T> } }); _buffer.LinkTo(actionBlock, new DataflowLinkOptions { PropagateCompletion = true }); } -
mnadel revised this gist
Nov 7, 2015 . No changes.There are no files selected for viewing
-
mnadel created this gist
Nov 7, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ using System.Threading; using System.Threading.Tasks.Dataflow; class Pipeline<T> { private readonly SemaphoreSlim _semaphore; private readonly BufferBlock<T> _buffer; Pipeline(Action<T> action, int capacity) { _semaphore = new SemaphoreSlim(capacity, capacity); _buffer = new BufferBlock<T>(); var actionBlock = new ActionBlock<T>(t => { try { action(t); } finally { _semaphore.Release(); } }); _buffer.LinkTo (actionBlock, new DataflowLinkOptions { PropagateCompletion = true }); } void Post(T message) { _semaphore.Wait(); _buffer.Post(message); } }