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

Add MonadAwait instance to Awaitable

parent eeaa3143
No related branches found
No related tags found
No related merge requests found
...@@ -103,11 +103,14 @@ instance IsAwaitable r (Awaitable r) where ...@@ -103,11 +103,14 @@ instance IsAwaitable r (Awaitable r) where
cacheAwaitable (Awaitable x) = cacheAwaitable x cacheAwaitable (Awaitable x) = cacheAwaitable x
toAwaitable = id toAwaitable = id
instance MonadAwait Awaitable where
await = toAwaitable
instance Functor Awaitable where instance Functor Awaitable where
fmap fn (Awaitable x) = fnAwaitable $ fn <$> runAwaitable x fmap fn (Awaitable x) = fnAwaitable $ fn <$> runAwaitable x
instance Applicative Awaitable where instance Applicative Awaitable where
pure value = fnAwaitable $ pure value pure = successfulAwaitable
liftA2 fn (Awaitable fx) (Awaitable fy) = fnAwaitable $ liftA2 fn (runAwaitable fx) (runAwaitable fy) liftA2 fn (Awaitable fx) (Awaitable fy) = fnAwaitable $ liftA2 fn (runAwaitable fx) (runAwaitable fy)
instance Monad Awaitable where instance Monad Awaitable where
...@@ -158,6 +161,7 @@ instance IsAwaitable r (CompletedAwaitable r) where ...@@ -158,6 +161,7 @@ instance IsAwaitable r (CompletedAwaitable r) where
completedAwaitable :: Either SomeException r -> Awaitable r completedAwaitable :: Either SomeException r -> Awaitable r
completedAwaitable result = toAwaitable $ CompletedAwaitable result completedAwaitable result = toAwaitable $ CompletedAwaitable result
-- | Alias for `pure`.
successfulAwaitable :: r -> Awaitable r successfulAwaitable :: r -> Awaitable r
successfulAwaitable = completedAwaitable . Right successfulAwaitable = completedAwaitable . Right
......
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