Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/ZeroMessenger/AnonymousMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ protected override ValueTask HandleAsyncCore(T message, CancellationToken cancel
{
return handler(message, cancellationToken);
}
}
}

internal sealed class AnonymousAsyncMessageHandler<T, TState>(TState state, Func<T, TState, CancellationToken, ValueTask> handler) : AsyncMessageHandler<T>
{
protected override ValueTask HandleAsyncCore(T message, CancellationToken cancellationToken = default)
{
return handler(message, state, cancellationToken);
}
}
8 changes: 7 additions & 1 deletion src/ZeroMessenger/MessageSubscriberExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ public static IDisposable SubscribeAwait<T>(this IMessageSubscriber<T> subscribe
{
return subscriber.SubscribeAwait(new AnonymousAsyncMessageHandler<T>(handler), subscribeStrategy);
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IDisposable SubscribeAwait<T, TState>(this IMessageSubscriber<T> subscriber, TState state, Func<T, TState, CancellationToken, ValueTask> handler, AsyncSubscribeStrategy subscribeStrategy = AsyncSubscribeStrategy.Sequential)
{
return subscriber.SubscribeAwait(new AnonymousAsyncMessageHandler<T, TState>(state, handler), subscribeStrategy);
}
}