You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ghci> a <- async (pure 3)
ghci> a' = fmap (+1) a
ghci> a == a'
True
ghci> wait a
3
ghci> wait a'
4
That doesn't make any sense to me. I think it would be better to remove the Eq and Ord instances and just provide custom comparison operations that explicitly operate only on the thread IDs.
-- Any instead of a proper existential so this can unpackdataAsynca=Async{asyncThreadId::!ThreadId
, _resVar::!(TMVar (EitherSomeExceptionAny))
, _resMod:: (Any->a) }instanceFunctorAsyncwherefmap f (Async tid rv g) =Async tid rv (f . g)
-- Note that <$ replaces the function instead of adding onto it
x <$Async tid rv _ =Async tid rv (const x)
dataSomeAsync=SomeAsync_!ThreadId!(TMVar (EitherSomeExceptionAny))
instanceOrdSomeAsyncwherecompare (SomeAsync tid1 _) (SomeAsync tid2 _) =compare tid1 tid2
patternSomeAsync::MyAsynca->SomeAsyncpatternSomeAsync x <- ((\(SomeAsync_ tid mv) ->MyAsync tid mv (const())) -> x)
whereSomeAsync (MyAsync tid tmv _) =SomeAsync_ tid tmv
Another variation on that last is to make SomeAsync a newtype around Async, using the tricks in the some package. That could be good for things like cancelMany.
We should have that, yes, but I think sometimes people want to be able to do things like use Asyncs for Set or Map keys for whatever reason. SomeAsync, by any implementation, allows that.
cancelMany would also be more useful if it took [SomeAsync] instead of [Async a]. Do you have an opinion about which SomeAsync representation to use? I'm partial to the approach of separating the TMVar from the mapping function myself—while that makes the Async heap object one word larger, it reduces the size of the function closure and allows for a more efficient <$>.
Not to leave this hanging indefinitely - basically I consider this "bug" to be something of a technicality. If we fix it, the cure better not be worse than the disease, and the disease is pretty mild IMO.
Activity
treeowl commentedon Mar 3, 2023
We could have a
SomeAsyncwith legitimate instances.The simple way:
Alternatively, we could do this:
Another variation on that last is to make
SomeAsynca newtype aroundAsync, using the tricks in thesomepackage. That could be good for things likecancelMany.simonmar commentedon Mar 3, 2023
Not a big fan of
SomeAsync, why not just havesameAsync :: Async a -> Async b -> Bool?treeowl commentedon Mar 3, 2023
We should have that, yes, but I think sometimes people want to be able to do things like use
Asyncs forSetorMapkeys for whatever reason.SomeAsync, by any implementation, allows that.simonmar commentedon Mar 3, 2023
Ok, fair point.
treeowl commentedon Mar 3, 2023
cancelManywould also be more useful if it took[SomeAsync]instead of[Async a]. Do you have an opinion about whichSomeAsyncrepresentation to use? I'm partial to the approach of separating theTMVarfrom the mapping function myself—while that makes theAsyncheap object one word larger, it reduces the size of the function closure and allows for a more efficient<$>.simonmar commentedon Sep 3, 2023
Not to leave this hanging indefinitely - basically I consider this "bug" to be something of a technicality. If we fix it, the cure better not be worse than the disease, and the disease is pretty mild IMO.