Skip to content

Commit

Permalink
Improved stability of pending task dictionary.
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferStrube committed Jun 18, 2024
1 parent a0b8ffa commit e473c50
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/KristofferStrube.Blazor.WebWorkers/JobWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public async Task<TOutput> ExecuteAsync(TInput input)
await eventListener.DisposeAsync();

JSONJob<object, object>.JobResponse response = await e.GetDataAsync<JSONJob<object, object>.JobResponse>();
pendingTasks[response.RequestIdentifier].SetResult(JsonSerializer.Deserialize<TOutput>(response.OutputSerialized)!);
if (pendingTasks.Remove(response.RequestIdentifier, out var successTaskCompletionSource))
{
successTaskCompletionSource.SetResult(JsonSerializer.Deserialize<TOutput>(response.OutputSerialized)!);
}
});

await AddOnMessageEventListenerAsync(eventListener);
Expand Down

0 comments on commit e473c50

Please sign in to comment.