I am rewriting some legacy C# classes into F#. One of the classes implements the IIdentityMessageService with the single method of this.SendAsync(identityMessage)
In the C# code, I see this
if (transportWeb != null)
return transportWeb.DeliverAsync(message);
else
return Task.FromResult(0);
I tried it in F# like this
if transportWeb != null then
transportWeb.DeliverAsync(message)
else
Task.FromResult(0)
and I am getting an error on the last line
This expression was expected to have type
Task
but here has type
Task<'a>
What am I missing? Thanks
It looks like DeliverAsync
returns a Task
, so you need both branches to return a Task
. Task.FromResult(0)
returns a Task<int>
so you need to explictly upcast it to a Task
:
else
Task.FromResult(0) :> Task
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With