module System.Directory.Watchman.SyncTimeout
    ( HasSyncTimeoutOption(..)

    , syncTimeout
    , syncOff
    ) where

class HasSyncTimeoutOption a where
    setSyncTimeout :: Maybe Int -> a -> a

-- | Set the timeout value for query synchronization. If the timeout passes, the command will return with an error.
syncTimeout
    :: HasSyncTimeoutOption a
    => Int -- ^ Time to wait in milliseconds
    -> (a -> a)
syncTimeout :: Int -> a -> a
syncTimeout Int
n = Maybe Int -> a -> a
forall a. HasSyncTimeoutOption a => Maybe Int -> a -> a
setSyncTimeout (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
n)

-- | Disable query synchronization for this command.
--
-- The query will be evaluated over the present view of the tree, which may lag behind the present state of the filesystem.
syncOff :: HasSyncTimeoutOption a => (a -> a)
syncOff :: a -> a
syncOff = Maybe Int -> a -> a
forall a. HasSyncTimeoutOption a => Maybe Int -> a -> a
setSyncTimeout (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
0)