diff --git a/test/Quasar/AwaitableSpec.hs b/test/Quasar/AwaitableSpec.hs index 77c9995a899c00de7527b459b93b7d4b96438c19..4b19f1e0cc7690f7f1f1016d52817645cb13ad70 100644 --- a/test/Quasar/AwaitableSpec.hs +++ b/test/Quasar/AwaitableSpec.hs @@ -11,6 +11,10 @@ import System.Timeout spec :: Spec spec = parallel $ do + describe "Awaitable" $ do + it "can await pure values" $ do + awaitIO $ (pure () :: Awaitable ()) :: IO () + describe "AsyncVar" $ do it "can be created" $ do _ <- newAsyncVar :: IO (AsyncVar ()) @@ -20,6 +24,42 @@ spec = parallel $ do avar <- newAsyncVar :: IO (AsyncVar ()) putAsyncVar_ avar () + it "can be awaited" $ do + avar <- newAsyncVar :: IO (AsyncVar ()) + putAsyncVar_ avar () + + awaitIO avar + + it "can be awaited and completed later" $ do + avar <- newAsyncVar :: IO (AsyncVar ()) + void $ forkIO $ do + threadDelay 100000 + putAsyncVar_ avar () + + awaitIO avar + + + describe "awaitAny" $ do + it "works with completed awaitables" $ do + awaitIO (awaitAny2 (pure () :: Awaitable ()) (pure () :: Awaitable ())) :: IO () + + it "can be completed later" $ do + avar1 <- newAsyncVar :: IO (AsyncVar ()) + avar2 <- newAsyncVar :: IO (AsyncVar ()) + void $ forkIO $ do + threadDelay 100000 + putAsyncVar_ avar1 () + awaitIO (awaitAny2 avar1 avar2) + + it "can be completed later by the second parameter" $ do + avar1 <- newAsyncVar :: IO (AsyncVar ()) + avar2 <- newAsyncVar :: IO (AsyncVar ()) + void $ forkIO $ do + threadDelay 100000 + putAsyncVar_ avar2 () + awaitIO (awaitAny2 avar1 avar2) + + describe "AsyncIO" $ do it "binds pure operations" $ do withDefaultAsyncManager (pure () >>= \() -> pure ())