Class Mailbox<TPayload>
- Namespace
- PatternKit.Messaging.Mailboxes
- Assembly
- PatternKit.Core.dll
In-process mailbox that serializes asynchronous message handling through a single consumer.
public sealed class Mailbox<TPayload> : IDisposable
Type Parameters
TPayloadThe payload type accepted by the mailbox.
- Inheritance
-
Mailbox<TPayload>
- Implements
- Inherited Members
Properties
Capacity
The configured bounded capacity, or null for an unbounded mailbox.
public int? Capacity { get; }
Property Value
- int?
IsAccepting
Gets whether the mailbox is accepting posts.
public bool IsAccepting { get; }
Property Value
QueuedCount
The current queued message count.
public int QueuedCount { get; }
Property Value
Methods
Create(MessageHandler)
Creates a mailbox builder with the supplied handler.
public static Mailbox<TPayload>.Builder Create(Mailbox<TPayload>.MessageHandler handler)
Parameters
handlerMailbox<TPayload>.MessageHandler
Returns
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
PostAsync(Message<TPayload>, MessageContext?, CancellationToken)
Posts a message to the mailbox.
public ValueTask<MailboxPostResult> PostAsync(Message<TPayload> message, MessageContext? context = null, CancellationToken cancellationToken = default)
Parameters
messageMessage<TPayload>contextMessageContextcancellationTokenCancellationToken
Returns
StartAsync(CancellationToken)
Starts the mailbox single-consumer pump.
public ValueTask StartAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
StopAsync(bool, CancellationToken)
Stops the mailbox and optionally drains queued messages before completing.
public ValueTask StopAsync(bool drain = true, CancellationToken cancellationToken = default)
Parameters
drainboolcancellationTokenCancellationToken