Table of Contents

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

TPayload

The 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

bool

QueuedCount

The current queued message count.

public int QueuedCount { get; }

Property Value

int

Methods

Create(MessageHandler)

Creates a mailbox builder with the supplied handler.

public static Mailbox<TPayload>.Builder Create(Mailbox<TPayload>.MessageHandler handler)

Parameters

handler Mailbox<TPayload>.MessageHandler

Returns

Mailbox<TPayload>.Builder

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

message Message<TPayload>
context MessageContext
cancellationToken CancellationToken

Returns

ValueTask<MailboxPostResult>

StartAsync(CancellationToken)

Starts the mailbox single-consumer pump.

public ValueTask StartAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

ValueTask

StopAsync(bool, CancellationToken)

Stops the mailbox and optionally drains queued messages before completing.

public ValueTask StopAsync(bool drain = true, CancellationToken cancellationToken = default)

Parameters

drain bool
cancellationToken CancellationToken

Returns

ValueTask