Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit 2d73e04

Browse files
committed
Make Utf8JsonWriter non thread static
1 parent 47d60b6 commit 2d73e04

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

samples/AspNetCoreSseServer/SseServerStreamTransport.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@ namespace AspNetCoreSseServer;
1010

1111
public class SseServerStreamTransport(Stream sseResponseStream) : ITransport
1212
{
13-
[ThreadStatic]
14-
private static Utf8JsonWriter? _jsonWriter;
15-
1613
private readonly Channel<IJsonRpcMessage> _incomingChannel = CreateSingleItemChannel<IJsonRpcMessage>();
1714
private readonly Channel<SseItem<IJsonRpcMessage?>> _outgoingSseChannel = CreateSingleItemChannel<SseItem<IJsonRpcMessage?>>();
1815

1916
private Task? _sseWriteTask;
17+
private Utf8JsonWriter? _jsonWriter;
2018

2119
public bool IsConnected => _sseWriteTask?.IsCompleted == false;
2220

2321
public Task RunAsync(CancellationToken cancellationToken)
2422
{
25-
static void WriteJsonRpcMessageToBuffer(SseItem<IJsonRpcMessage?> item, IBufferWriter<byte> writer)
23+
void WriteJsonRpcMessageToBuffer(SseItem<IJsonRpcMessage?> item, IBufferWriter<byte> writer)
2624
{
2725
if (item.EventType == "endpoint")
2826
{
@@ -70,7 +68,7 @@ private static Channel<T> CreateSingleItemChannel<T>() =>
7068
SingleWriter = false,
7169
});
7270

73-
private static Utf8JsonWriter GetUtf8JsonWriter(IBufferWriter<byte> writer)
71+
private Utf8JsonWriter GetUtf8JsonWriter(IBufferWriter<byte> writer)
7472
{
7573
if (_jsonWriter is null)
7674
{

0 commit comments

Comments
 (0)