Skip to content

Commit

Permalink
Added FullMode overload (#1800)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hulkstance committed Oct 13, 2022
1 parent 261f15b commit 12896af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Proto.Actor/Mailbox/BoundedMailboxQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ public class BoundedMailboxQueue : IMailboxQueue
private volatile bool _hasMessages;
private long _length;

public BoundedMailboxQueue(int size)
public BoundedMailboxQueue(int size, BoundedChannelFullMode fullMode = BoundedChannelFullMode.Wait)
{
_messages = Channel.CreateBounded<object>(size);
_messages = Channel.CreateBounded<object>(new BoundedChannelOptions(size)
{
FullMode = fullMode
});
}

public int Length => (int)Interlocked.Read(ref _length);
Expand Down
4 changes: 4 additions & 0 deletions src/Proto.Actor/Mailbox/Mailbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;

namespace Proto.Mailbox;
Expand Down Expand Up @@ -34,6 +35,9 @@ public static class BoundedMailbox
{
public static IMailbox Create(int size, params IMailboxStatistics[] stats) =>
new DefaultMailbox(new LockingUnboundedMailboxQueue(4), new BoundedMailboxQueue(size), stats);

public static IMailbox Create(int size, BoundedChannelFullMode fullMode, params IMailboxStatistics[] stats) =>
new DefaultMailbox(new LockingUnboundedMailboxQueue(4), new BoundedMailboxQueue(size, fullMode), stats);
}

public static class UnboundedMailbox
Expand Down

0 comments on commit 12896af

Please sign in to comment.