Skip to content

Add async serialization support#1574

Merged
jeremydmiller merged 1 commit intoJasperFx:mainfrom
dominikjeske:features/asyncSerializer
Jul 22, 2025
Merged

Add async serialization support#1574
jeremydmiller merged 1 commit intoJasperFx:mainfrom
dominikjeske:features/asyncSerializer

Conversation

@dominikjeske
Copy link
Copy Markdown
Contributor

No description provided.

get => _scheduleDelay;
}

public async ValueTask<byte[]?> GetDataAsync()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is additive change GetDataAsync can be executed and it fallback to Data

}
AssertMessage();

if(Serializer is IAsyncMessageSerializer asyncMessaeSerializer)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use only when serializer support async

@dominikjeske dominikjeske force-pushed the features/asyncSerializer branch from a0867fd to 464a822 Compare July 18, 2025 14:54
/// <summary>
/// Async version of <seealso cref="IMessageSerializer"/>
/// </summary>
public interface IAsyncMessageSerializer : IMessageSerializer
Copy link
Copy Markdown
Contributor Author

@dominikjeske dominikjeske Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We extend standard serializer so nothing is changing in code - envelope serializer type is still IMessageSerializer

}

public bool TryDeserializeEnvelope(Envelope envelope, out IContinuation continuation)
public async ValueTask<IContinuation> TryDeserializeEnvelope(Envelope envelope)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method signature is changing - for me it is even better because it is more function like - one result instead two (bool and IContinuation)

if (_graph.TryFindMessageType(envelope.MessageType, out var messageType))
{
envelope.Message = serializer.ReadFromData(messageType, envelope);
if (serializer is IAsyncMessageSerializer asyncMessageSerializer)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use async if it implement this

Task InvokeAsync(Envelope envelope, IChannelCallback channel);
Task InvokeAsync(Envelope envelope, IChannelCallback channel, Activity activity);
bool TryDeserializeEnvelope(Envelope envelope, out IContinuation continuation);
ValueTask<IContinuation> TryDeserializeEnvelope(Envelope envelope);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only one potential breaking change but I'm wonder if this interface should be public? Maybe it should be internal or nobody is executing this so event public we don't break anything

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be part of the public interface. It's just a detail of the HandlerPipeline details

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremydmiller So I think it should be no problem with change :) As a note in our company we use MS https://www.nuget.org/packages/Microsoft.CodeAnalysis.PublicApiAnalyzers/ to keep public API stable. It reminds to keep internal things (when things are internal your life is easier because analyser is not screaming in your face :) ). You have to use to this analyser especially when adding new API but tooling is quite good (especially "use this for whole project/solution" so you can add new API's in one click.

@dominikjeske dominikjeske force-pushed the features/asyncSerializer branch 2 times, most recently from 3171f71 to a12297c Compare July 19, 2025 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants