Skip to content

IRenderedComponent.InvokeAsync should support return values #1296

@Jcparkyn

Description

@Jcparkyn

Is the feature request related to a problem? Please elaborate.

I have a method I want to test that triggers a re-render via StateHasChanged, and also returns a value. Due to the re-render, I need to call this inside cut.InvokeAsync, which doesn't provide a way to access the return value.

The suggested solution

Add new overloads for InvokeAsync that return the value returned by workItem. E.g.:

public static Task<T> InvokeAsync<T>(this IRenderedFragmentBase renderedFragment, Func<T> workItem)
public static Task<T> InvokeAsync<T>(this IRenderedFragmentBase renderedFragment, Func<Task<T>> workItem)

Conveniently, these don't need any changes to the method body, since Dispatcher already has the necessary overloads.

This might cause some existing code to start depending on the new overloads, but as far as I can tell there wouldn't be any breaking changes due to this.

Describe any alternative solutions

None that I can think of.

Additional context

n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions