Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

.NET – How can I convert a Task<> to Task (with no type parameter)?

Task<T> is a separate class from Task (no type parameter), and there are some functions that only accept untyped Task as a parameter. How can I convert a Task<T> to a Task (with no type parameter)?

Examples in F#, but same principle applies to C#.

This F# function:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

let getTask = task {
    return ()
}

creates a Task<unit>.

>Solution :

You can just cast:

let t = getTask() :> Task

-Also, FSharp.Control.FusionTasks has a bunch of helper functions. In this case, it’d be Task.ignore.- edit: it’s a different lib, lemmecheck on that, brb.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading