module Ki.Unlifted
( Ki.Scope,
Ki.Thread,
scoped,
fork,
forkTry,
Ki.await,
Ki.awaitAll,
fork_,
forkWith,
forkWith_,
forkTryWith,
Ki.ThreadOptions (..),
Ki.defaultThreadOptions,
Ki.ThreadAffinity (..),
Ki.ByteCount,
Ki.kilobytes,
Ki.megabytes,
)
where
import Control.Exception (Exception)
import Control.Monad.IO.Unlift (MonadUnliftIO (withRunInIO))
import Data.Void (Void)
import qualified Ki
import Prelude
fork :: forall a m. MonadUnliftIO m => Ki.Scope -> m a -> m (Ki.Thread a)
fork :: Scope -> m a -> m (Thread a)
fork Scope
scope m a
action =
((forall a. m a -> IO a) -> IO (Thread a)) -> m (Thread a)
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO \forall a. m a -> IO a
unlift -> Scope -> IO a -> IO (Thread a)
forall a. Scope -> IO a -> IO (Thread a)
Ki.fork Scope
scope (m a -> IO a
forall a. m a -> IO a
unlift m a
action)
fork_ :: MonadUnliftIO m => Ki.Scope -> m Void -> m ()
fork_ :: Scope -> m Void -> m ()
fork_ Scope
scope m Void
action =
((forall a. m a -> IO a) -> IO ()) -> m ()
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO \forall a. m a -> IO a
unlift -> Scope -> IO Void -> IO ()
Ki.fork_ Scope
scope (m Void -> IO Void
forall a. m a -> IO a
unlift m Void
action)
forkWith :: forall a m. MonadUnliftIO m => Ki.Scope -> Ki.ThreadOptions -> m a -> m (Ki.Thread a)
forkWith :: Scope -> ThreadOptions -> m a -> m (Thread a)
forkWith Scope
scope ThreadOptions
opts m a
action =
((forall a. m a -> IO a) -> IO (Thread a)) -> m (Thread a)
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO \forall a. m a -> IO a
unlift -> Scope -> ThreadOptions -> IO a -> IO (Thread a)
forall a. Scope -> ThreadOptions -> IO a -> IO (Thread a)
Ki.forkWith Scope
scope ThreadOptions
opts (m a -> IO a
forall a. m a -> IO a
unlift m a
action)
forkWith_ :: MonadUnliftIO m => Ki.Scope -> Ki.ThreadOptions -> m Void -> m ()
forkWith_ :: Scope -> ThreadOptions -> m Void -> m ()
forkWith_ Scope
scope ThreadOptions
opts m Void
action =
((forall a. m a -> IO a) -> IO ()) -> m ()
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO \forall a. m a -> IO a
unlift -> Scope -> ThreadOptions -> IO Void -> IO ()
Ki.forkWith_ Scope
scope ThreadOptions
opts (m Void -> IO Void
forall a. m a -> IO a
unlift m Void
action)
forkTry :: (Exception e, MonadUnliftIO m) => Ki.Scope -> m a -> m (Ki.Thread (Either e a))
forkTry :: Scope -> m a -> m (Thread (Either e a))
forkTry Scope
scope m a
action =
((forall a. m a -> IO a) -> IO (Thread (Either e a)))
-> m (Thread (Either e a))
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO \forall a. m a -> IO a
unlift -> Scope -> IO a -> IO (Thread (Either e a))
forall e a.
Exception e =>
Scope -> IO a -> IO (Thread (Either e a))
Ki.forkTry Scope
scope (m a -> IO a
forall a. m a -> IO a
unlift m a
action)
forkTryWith ::
(Exception e, MonadUnliftIO m) =>
Ki.Scope ->
Ki.ThreadOptions ->
m a ->
m (Ki.Thread (Either e a))
forkTryWith :: Scope -> ThreadOptions -> m a -> m (Thread (Either e a))
forkTryWith Scope
scope ThreadOptions
opts m a
action =
((forall a. m a -> IO a) -> IO (Thread (Either e a)))
-> m (Thread (Either e a))
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO \forall a. m a -> IO a
unlift -> Scope -> ThreadOptions -> IO a -> IO (Thread (Either e a))
forall e a.
Exception e =>
Scope -> ThreadOptions -> IO a -> IO (Thread (Either e a))
Ki.forkTryWith Scope
scope ThreadOptions
opts (m a -> IO a
forall a. m a -> IO a
unlift m a
action)
scoped :: forall a m. MonadUnliftIO m => (Ki.Scope -> m a) -> m a
scoped :: (Scope -> m a) -> m a
scoped Scope -> m a
action =
((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO \forall a. m a -> IO a
unlift -> (Scope -> IO a) -> IO a
forall a. (Scope -> IO a) -> IO a
Ki.scoped \Scope
scope -> m a -> IO a
forall a. m a -> IO a
unlift (Scope -> m a
action Scope
scope)