DUCKY010: Blocking on a Ducky task
Package: Ducky (analyzer Ducky.Generators). Surface: build warning on the blocking expression (SPEC §7, §16.2,
ADR-0014).
What happened
The task of DispatchAsync, SetAsync, WhenIdleAsync, WhenRenderedAsync (Ducky.Blazor's test settle) or InitializeAsync (on IStore, IDispatcher,
EffectContext, Middleware, SliceStore, DuckyComponent, DuckyLayout or Ducky.Testing's TestStore) is waited on synchronously with .Result,
.Wait() or GetAwaiter().GetResult(), through ConfigureAwait(...) too. These tasks complete only once the store's
drainer makes progress: if the caller is the drainer, the wait is a self-deadlock, and Blazor WebAssembly has a single
thread, where such a wait can never complete.
Only a call written in place is seen: storing the task in a variable and waiting on it later is not reported, and blocks just the same.
For example, this code is reported:
using Ducky;
public sealed record Refresh;
public sealed class RefreshButton(IStore store)
{
public void OnClick() => store.DispatchAsync(new Refresh()).Wait();
}How to fix it
await the task. To fire an action without waiting, call Dispatch (or Set instead of SetAsync); to wait for the
store to settle in a test, await WhenIdleAsync(), or await store.WhenRenderedAsync(Renderer.Dispatcher) when a bUnit-rendered component must have rendered too.