Skip to content

Instantly share code, notes, and snippets.

@zHaytam
Created March 21, 2021 11:41
Show Gist options
  • Save zHaytam/60636536895c681a8f9517e490c80b78 to your computer and use it in GitHub Desktop.
Save zHaytam/60636536895c681a8f9517e490c80b78 to your computer and use it in GitHub Desktop.
Task IHandleEvent.HandleEventAsync(EventCallbackWorkItem callback, object? arg)
{
var task = callback.InvokeAsync(arg);
var shouldAwaitTask = task.Status != TaskStatus.RanToCompletion &&
task.Status != TaskStatus.Canceled;
// After each event, we synchronously re-render (unless !ShouldRender())
// This just saves the developer the trouble of putting "StateHasChanged();"
// at the end of every event callback.
StateHasChanged();
return shouldAwaitTask ?
CallStateHasChangedOnAsyncCompletion(task) :
Task.CompletedTask;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment