IO improvements #1519
louthy
announced in
Announcements
IO improvements
#1519
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
awaitAnyimprovedThe
awaitAnyfunction - that works with anyMonadUnliftIOtrait-implementing type (IO,Eff, etc.), accepts a number of asynchronous computations, and returns when the first computation completes (a functional version ofTask.WhenAny) - will now cancel all computations once the first one has completed. This is probably the most desirable default functionality, rather than letting all computations continue until they're complete.This example will only write out
"C", theAandBprocesses will be cancelled once theCprocess completes:UninterruptibleIOThe
MonadUnliftIOtrait now has a new method:UninterruptibleIO:The default behaviour is to block cancellation-requests that are raised via the
EnvIOcancellation-token. It does this by creating a new local-EnvIOcontext that ignores the parent's cancellation context.There's an
UninterruptibleIOextension method and anuninterruptiblefunction in thePreludethat will work with anyMonadUnliftIOtrait-implementing type (IO,Eff, etc.).If you wished to go back to the old
awaitAnybehaviour then you can wrap each computation withuninterruptible(...). If we do that with the previous example:Then the output will be:
Which was the previous default functionality.
Timeout improvements
EnvIO- aTimeSpancan be provided for whenCancellationTokenSourceisnulland it will then use that timeout value when constructing a new one.EnvIO.LocalWithTimeout(TimeSpan)andEnvIO.LocalCancelWithTimeout(TimeSpan), which are the most useful functions as they allow for a local context with a timeout attached.IO<A>.Timeout,IO.timeout, andPrelude.timeoutfunctions have been improved to leverage this new functionality. The previous implementation was quite naive and not the most efficient, so this needed doing.Effects prelude
I've moved the more general (
K<M, A>) based IO operators/functions to the root of theEffectsfolder to show they're general and not just for the IO type. It makes functions slightly more discoverable in the API documentation.This discussion was created from the release IO improvements.
Beta Was this translation helpful? Give feedback.
All reactions