Skip to content

Semialign Concurrently #199

Description

@Jashweii

I'm not sure this is useful, but it might be interesting or show up elsewhere.
https://hackage.haskell.org/package/async provides:

type Concurrently :: * -> * -- newtype of IO, instances run things in parallel
instance Applicative Concurrently -- <*> = concurrently (wait for both)
instance Alternative Concurrently -- <|> = race (wait for first)

It could have

instance Semialign Concurrently -- align = ??? (wait for first, but keep both if the other is done)

When one task completes, a cancel exception is thrown to the other.
But if the other is already done before that signal is received it can give back both.

With that said, this is probably not very useful since you're very unlikely to have two tasks finish within such a short overlapping time frame. Maybe if you had a long uninterruptible call this would be useful. A timed version might be useful:

-- Race, once the first completes, if the other completes within the timeout give back both results
??? :: Double {- timeout after first result -} -> IO a -> IO b -> IO (These a b)

Or you could imagine some library where a task can choose to submit a result and continue before sending a kill signal (which could achieve the timed version).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions