Allow bounded channel to be created with drop delegate (#50331)
authorIvan Beňovic <Ivan.Benovic2@gmail.com>
Wed, 31 Mar 2021 11:13:59 +0000 (13:13 +0200)
committerGitHub <noreply@github.com>
Wed, 31 Mar 2021 11:13:59 +0000 (07:13 -0400)
commitb47094da840f8b775fbadea5c5739022a951ac84
tree13c25b9b7048a9b9c4d9c71019990b61f52e687b
parenta913740aac5353212a9b95283ae38b9964f18aa5
Allow bounded channel to be created with drop delegate (#50331)

* Bounded channel can be created with drop delegate.

- Add additional CreateBounded overload with delegate parameter that will be called when item is being dropped from channel
- Added unit tests

* Fix typo in comment.

* Apply suggestions from code review

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Call drop delegate outside of lock statement.

* Use overload of CreateBounded method instead of calling ctor directly.

* Code review suggestions refactor.

* Move Monitor.Enter before try and use local scoped parent variable everywhere.

* Drop delegate should not be called while sync lock is held.

Enqueuing of new item should be done while sync lock is being held.
Added additional tests.

* Rerun gitlab CI.

* Do not run deadlock test for bounded channels if platform do not support threading.

* Apply suggestions from code review

Co-authored-by: Ivan Benovic <ivan.benovic@innovatrics.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
src/libraries/System.Threading.Channels/ref/System.Threading.Channels.cs
src/libraries/System.Threading.Channels/src/System/Threading/Channels/BoundedChannel.cs
src/libraries/System.Threading.Channels/src/System/Threading/Channels/Channel.cs
src/libraries/System.Threading.Channels/tests/BoundedChannelTests.cs