What types should async methods return #1385
-
|
Hi, I trying to wrap my head around synchrony with LangExt but I am stuck on the simplest thing: I'd like my services like IFileDownlaoder to return OptionAsync<byte[]> instead of Task<Option<byte[]>> but implantation as simple as fails to compile with error: Indeed, when looking upon implementations OptionAsync nor EitherAsync implement custom awaitables and related async machinery. So: what the return types of async methods should be so that functional pipelines could be built from LangExt types? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
If you haven't started using the If you want to continue with static OptionAsync<int> GetIntAsync() =>
from _ in SomeAsync(wait(1))
select 42;
static async Task<Unit> wait(int seconds)
{
await Task.Delay(TimeSpan.FromSeconds(1));
return unit;
}So, all of the standard functional operators ( In version 5 you'd use the static OptionT<IO, int> GetIntAsync() =>
from _ in wait(1)
select 42;
static IO<Unit> wait(int seconds) =>
liftIO(async e => await Task.Delay(TimeSpan.FromSeconds(1), e.Token));The benefit of the new approach is:
|
Beta Was this translation helpful? Give feedback.
If you haven't started using the
*Asyncvariants yet, then you may want to skip them and go straight tov5. The proposal to remove the*Asyncvariants has been acted upon and they don't exist any more.If you want to continue with
OptionAsynconv4then you use LINQ, not async/await:So, all of the standard functional operators (
Map,Bind,Apply, etc.) understand the asynchrony and apply it as part of their implementations.In version 5 you'd use the
IOmonad (support for async essentially) w…