Intended way to call async and ignore result
jbtule opened this issue · comments
do!
isn't happy with a Task<_>
and let! _ =
can be a work around, but not very readable.
FSharp Async as Async.Ignore
. But I don't see an equivalent with this library, and it seems like there should be.
Since Task<_> inherits from Task, I'm thinking
let Ignore (resultTask:Task<_>): Task = upcast resultTask
should work. But we are in the middle of porting some C# to F# code, and haven't tested it other than type checking wise it appears to work.
I was wondering if this is an issue anyone has dealt with.
Thanks,
I just use let! _ =
in my own code. It does look a little odd but in my view, it is equally or slightly more clear what's happening in let! _ = someTask
compared to do! Task.Ignore(someTask)
.
You can't end a task { }
block with let! _ = ...
, but in my mind it reads fine to just add another line of return ()
.
Or just write do! ... :> Task
.
That said, if you prefer to use a wrapper function in your codebase there is nothing wrong with doing so.
Yeah the wrapper function did work for us, do! ... |> Task.Ignore
but I kinda like the do! ... :> Task
too.
module Task =
let Ignore (resultTask:Task<_>): Task = upcast resultTask
Thanks!