-- | Unlifted "System.Timeout".
--
-- @since 0.1.0.0
module UnliftIO.Timeout
  ( timeout
  ) where

import qualified System.Timeout as S
import Control.Monad.IO.Unlift

-- | Unlifted 'S.timeout'.
--
-- @since 0.1.0.0
timeout :: MonadUnliftIO m => Int -> m a -> m (Maybe a)
timeout :: forall (m :: * -> *) a.
MonadUnliftIO m =>
Int -> m a -> m (Maybe a)
timeout Int
x m a
y = ((forall a. m a -> IO a) -> IO (Maybe a)) -> m (Maybe a)
forall b. ((forall a. m a -> IO a) -> IO b) -> m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (((forall a. m a -> IO a) -> IO (Maybe a)) -> m (Maybe a))
-> ((forall a. m a -> IO a) -> IO (Maybe a)) -> m (Maybe a)
forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run -> Int -> IO a -> IO (Maybe a)
forall a. Int -> IO a -> IO (Maybe a)
S.timeout Int
x (IO a -> IO (Maybe a)) -> IO a -> IO (Maybe a)
forall a b. (a -> b) -> a -> b
$ m a -> IO a
forall a. m a -> IO a
run m a
y