Skip to content
Snippets Groups Projects
Commit 758a4bcf authored by Jens Nolte's avatar Jens Nolte
Browse files

Restrict types on awaitable helpers to fix type inference

parent f192a2b4
No related branches found
No related tags found
No related merge requests found
Pipeline #2566 passed
...@@ -431,7 +431,7 @@ afix_ = void . afix ...@@ -431,7 +431,7 @@ afix_ = void . afix
-- | Completes as soon as either awaitable completes. -- | Completes as soon as either awaitable completes.
awaitEither :: (IsAwaitable ra a, IsAwaitable rb b, MonadAwait m) => a -> b -> m (Either ra rb) awaitEither :: MonadAwait m => Awaitable ra -> Awaitable rb -> m (Either ra rb)
awaitEither x y = mkMonadicAwaitable $ stepBoth (runAwaitable x) (runAwaitable y) awaitEither x y = mkMonadicAwaitable $ stepBoth (runAwaitable x) (runAwaitable y)
where where
stepBoth :: MonadAwait m => AwaitableStepM ra -> AwaitableStepM rb -> m (Either ra rb) stepBoth :: MonadAwait m => AwaitableStepM ra -> AwaitableStepM rb -> m (Either ra rb)
...@@ -451,8 +451,8 @@ eitherSTM x y = fmap Left x `orElse` fmap Right y ...@@ -451,8 +451,8 @@ eitherSTM x y = fmap Left x `orElse` fmap Right y
-- Completes as soon as any awaitable in the list is completed and then returns the left-most completed result -- Completes as soon as any awaitable in the list is completed and then returns the left-most completed result
-- (or exception). -- (or exception).
awaitAny :: (IsAwaitable r a, MonadAwait m) => NonEmpty a -> m r awaitAny :: MonadAwait m => [Awaitable r] -> m r
awaitAny xs = mkMonadicAwaitable $ stepAll Empty Empty $ runAwaitable <$> fromList (toList xs) awaitAny xs = mkMonadicAwaitable $ stepAll Empty Empty $ runAwaitable <$> fromList xs
where where
stepAll stepAll
:: MonadAwait m :: MonadAwait m
...@@ -477,5 +477,5 @@ anySTM (x :| xs) = x `orElse` maybe retry anySTM (nonEmpty xs) ...@@ -477,5 +477,5 @@ anySTM (x :| xs) = x `orElse` maybe retry anySTM (nonEmpty xs)
-- | Like `awaitAny` with two awaitables. -- | Like `awaitAny` with two awaitables.
awaitAny2 :: (IsAwaitable r a, IsAwaitable r b, MonadAwait m) => a -> b -> m r awaitAny2 :: MonadAwait m => Awaitable r -> Awaitable r -> m r
awaitAny2 x y = awaitAny (toAwaitable x :| [toAwaitable y]) awaitAny2 x y = awaitAny [toAwaitable x, toAwaitable y]
...@@ -120,7 +120,7 @@ startSchedulerThread scheduler = toDisposable <$> unmanagedAsync (schedulerThrea ...@@ -120,7 +120,7 @@ startSchedulerThread scheduler = toDisposable <$> unmanagedAsync (schedulerThrea
wait :: Timer -> Int -> IO () wait :: Timer -> Int -> IO ()
wait nextTimer microseconds = do wait nextTimer microseconds = do
delay <- newUnmanagedDelay microseconds delay <- newUnmanagedDelay microseconds
awaitAny2 delay nextTimerChanged awaitAny2 (await delay) nextTimerChanged
dispose delay dispose delay
where where
nextTimerChanged :: Awaitable () nextTimerChanged :: Awaitable ()
......
...@@ -53,7 +53,7 @@ spec = parallel $ do ...@@ -53,7 +53,7 @@ spec = parallel $ do
void $ forkIO $ do void $ forkIO $ do
threadDelay 100000 threadDelay 100000
putAsyncVar_ avar1 () putAsyncVar_ avar1 ()
awaitAny2 avar1 avar2 awaitAny2 (await avar1) (await avar2)
it "can be completed later by the second parameter" $ do it "can be completed later by the second parameter" $ do
avar1 <- newAsyncVar :: IO (AsyncVar ()) avar1 <- newAsyncVar :: IO (AsyncVar ())
...@@ -61,7 +61,7 @@ spec = parallel $ do ...@@ -61,7 +61,7 @@ spec = parallel $ do
void $ forkIO $ do void $ forkIO $ do
threadDelay 100000 threadDelay 100000
putAsyncVar_ avar2 () putAsyncVar_ avar2 ()
awaitAny2 avar1 avar2 awaitAny2 (await avar1) (await avar2)
describe "cacheAwaitable" do describe "cacheAwaitable" do
it "can cache an awaitable" $ io do it "can cache an awaitable" $ io do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment