diff --git a/Examples/WebAssembly/Pages/Home.razor b/Examples/WebAssembly/Pages/Home.razor index be0ebd7..0462507 100644 --- a/Examples/WebAssembly/Pages/Home.razor +++ b/Examples/WebAssembly/Pages/Home.razor @@ -22,7 +22,7 @@ else {

Signatures remaining: @Xmss.SignaturesRemaining

-

Destroy

+

Destroy

Public Key

@@ -109,6 +109,7 @@ else async Task CalculatePublicKey() { + ProgressPercentage = 0; IsCalculating = true; CancellationTokenSource.Dispose(); diff --git a/Xmss/Xmss.cs b/Xmss/Xmss.cs index d75f92c..1604a19 100644 --- a/Xmss/Xmss.cs +++ b/Xmss/Xmss.cs @@ -72,8 +72,7 @@ public Xmss() static bool TriedRegisterOnce; /// - /// Registers the implementation with , such that it can be created - /// by name or . + /// Registers the class with , such that its is known and it can be created by name. /// /// /// @@ -530,6 +529,7 @@ public async Task CalculatePublicKeyAsync(Action? reportPercentage = nul var index = 0; var completed = 0; var lastReported = 0; + var lastDelay = Stopwatch.GetTimestamp(); using var cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); Exception? taskException = null; while (!cancellationTokenSource.IsCancellationRequested && completed < totalTaskCount) @@ -581,10 +581,17 @@ void HandleTaskCompletion() [ExcludeFromCodeCoverage(Justification = "Not testable; WASM only.")] Task OptionalDelayTask() { - // WASM is single-threaded; give the UI a chance - return RuntimeInformation.ProcessArchitecture == Architecture.Wasm && Environment.ProcessorCount == 1 - ? Task.Delay(TimeSpan.FromMilliseconds(1), cancellationToken) - : Task.CompletedTask; + if (RuntimeInformation.ProcessArchitecture == Architecture.Wasm && Environment.ProcessorCount == 1 + && Stopwatch.GetElapsedTime(lastDelay) > TimeSpan.FromMilliseconds(50)) + { + // On single threaded WASM we need to keep the UI responsive. + lastDelay = Stopwatch.GetTimestamp(); + return Task.Delay(TimeSpan.FromMilliseconds(1), cancellationToken); + } + else + { + return Task.CompletedTask; + } } await OptionalDelayTask().ConfigureAwait(false);