Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method that turns a Task into a Task<Unit> #394

Closed
Mafii opened this issue Jun 10, 2021 · 2 comments
Closed

Add method that turns a Task into a Task<Unit> #394

Mafii opened this issue Jun 10, 2021 · 2 comments
Assignees
Labels
area: Funcky.Async enhancement New feature or request

Comments

@Mafii
Copy link
Member

Mafii commented Jun 10, 2021

Name idea: VoidTaskToUnitTask or TaskToUnitTask

practical usages:

does not compile:

_ = test switch
{
    test is ISomeInterface some => await SomeMethodReturningTask(some),
    test is ISomeOtherInterface some => await SomeMethodReturningTask(some),
};

Would compile:

_ = test switch
{
    test is ISomeInterface some => await TaskToUnitTask(SomeMethodReturningTask(some)),
    test is ISomeOtherInterface some => await TaskToUnitTask(SomeMethodReturningTask(some)),
};

This feature could simplify some code and allow usage of switch expressions with await even when the Task is non-generic.

Currently you'd have to do this, which really is annoying:

var someTask = test switch
{
    test is ISomeInterface some => SomeMethodReturningTask(some),
    test is ISomeOtherInterface some => SomeMethodReturningTask(some),
};
await someTask;
@Mafii Mafii added the enhancement New feature or request label Jun 10, 2021
@bash
Copy link
Member

bash commented Jun 10, 2021

This should probably be called ActionToUnitAsync and for completeness we should also add UnitToActionAsync.

@bash
Copy link
Member

bash commented Sep 12, 2022

We think improvements to C# should be preferred to this approach.
For instance Switch expression as a statement expression.

@bash bash closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Funcky.Async enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants