Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SomeAsync and value replacement #144

Open
treeowl opened this issue Mar 3, 2023 · 1 comment
Open

SomeAsync and value replacement #144

treeowl opened this issue Mar 3, 2023 · 1 comment

Comments

@treeowl
Copy link
Contributor

treeowl commented Mar 3, 2023

cancelMany :: [Async a] -> IO () is ... okay, but it's annoying when cancelling Asyncs with multiple types. Some options:

-- Not very nice. Allocates wrappers unnecessarily.
data SomeAsync = forall a. SomeAsync !(Async a)
cancelSomeAsyncs :: [SomeAsync] -> IO ()

-- Is a `some` dependency okay, or copying stuff from there?
cancelSomeAsyncs :: [Some Async] -> IO ()

-- Potentially expensive if there's a lot of `fmap`ping and not a lot of inlining.
cancelAsyncs [() <$ thisOne, () <$ thatOne]

-- Can we make <$ cheaper? Yes, but it makes `Async` bigger. Any we need
-- to unsafeCoerce with Any to allow Async to unbox (ugh).
data Async a = Async !ThreadId !(TMVar (Either SomeException Any)) (Any -> a)
a <$ Async tid mv fun = Async tid mv (const a)

Nothing I'd call a beautiful solution.

@treeowl
Copy link
Contributor Author

treeowl commented Mar 3, 2023

Oh yeah, there's also the HListy option:

data Asyncs :: [Type] -> Type where
  Nil :: Asyncs '[]
  (:<) :: {-# UNPACK #-} (Async a) -> Asyncs as -> Asyncs (a ': as)

But a custom heterogeneous list type doesn't seem appropriate for this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant