-- | Functions and types for safely working with tempfiles in 'Scoped' blocks -- -- @since 0.1.0.0 module Control.Monad.Scoped.Temp ( -- * Allocating a temporary files in a 'Scoped' block tempFile , systemTempFile ) where import Control.Monad.Scoped.Handle (ScopedHandle) import Control.Monad.Scoped.Internal (Scoped (UnsafeMkScoped), ScopedResource (UnsafeMkScopedResource)) import UnliftIO (MonadUnliftIO, withSystemTempFile, withTempFile) -- | Like 'System.IO.withTempFile' but for 'Scoped' -- -- @since 0.1.0.0 tempFile :: MonadUnliftIO m => FilePath -> String -> Scoped (s : ss) m (FilePath, ScopedHandle s) tempFile fp template = UnsafeMkScoped \k -> withTempFile fp template \path h -> k (path, UnsafeMkScopedResource h) -- | Like 'System.IO.withSystemTempFile' but for 'Scoped' -- -- @since 0.1.0.0 systemTempFile :: MonadUnliftIO m => String -> Scoped (s : ss) m (FilePath, ScopedHandle s) systemTempFile template = UnsafeMkScoped \k -> withSystemTempFile template \path h -> k (path, UnsafeMkScopedResource h)