Add ki-unlifted package

This commit is contained in:
Mitchell Rosen 2021-11-30 17:35:51 -05:00
parent 3ee6d8c870
commit 352ef1161c
3 changed files with 171 additions and 1 deletions

View File

@ -1 +1 @@
packages: ki
packages: ki, ki-unlifted

View File

@ -0,0 +1,79 @@
cabal-version: 2.2
author: Mitchell Rosen
bug-reports: https://github.com/awkward-squad/ki/issues
category: Concurrency
copyright: Copyright (C) 2020-2021 Mitchell Rosen, Travis Staton
homepage: https://github.com/awkward-squad/ki
license: BSD-3-Clause
license-file: LICENSE
maintainer: Mitchell Rosen <mitchellwrosen@gmail.com>, Travis Staton <hello@travisstaton.com>
name: ki-unlifted
stability: experimental
synopsis: A lightweight structured-concurrency library
version: 0.3.0
description:
A lightweight structured-concurrency library.
extra-source-files:
CHANGELOG.md
README.md
source-repository head
type: git
location: https://github.com/awkward-squad/ki.git
common component
build-depends:
base >= 4.12.0.0 && < 4.17,
default-extensions:
AllowAmbiguousTypes
BangPatterns
BlockArguments
ConstraintKinds
DeriveAnyClass
DeriveDataTypeable
DeriveFunctor
DeriveGeneric
DerivingStrategies
DuplicateRecordFields
ExistentialQuantification
GeneralizedNewtypeDeriving
InstanceSigs
LambdaCase
NamedFieldPuns
NoImplicitPrelude
NumericUnderscores
PartialTypeSignatures
PatternSynonyms
RankNTypes
RoleAnnotations
ScopedTypeVariables
TypeApplications
ViewPatterns
default-language: Haskell2010
ghc-options:
-Weverything
-Wno-all-missed-specialisations
-Wno-implicit-prelude
-Wno-missed-specialisations
-Wno-missing-import-lists
-Wno-safe
-Wno-unsafe
if impl(ghc >= 8.10)
ghc-options:
-Wno-missing-safe-haskell-mode
-Wno-prepositive-qualified-module
if impl(ghc >= 9.2)
ghc-options:
-Wno-missing-kind-signatures
library
import: component
build-depends:
ki,
unliftio-core,
exposed-modules:
Ki.Unlifted
hs-source-dirs: src

View File

@ -0,0 +1,91 @@
-- | The "Ki" API, generalized to use 'MonadIO' and 'MonadUnliftIO'.
module Ki.Unlifted
( -- * Core API
-- ** Scope
Ki.Scope,
scoped,
wait,
-- ** Thread
Ki.Thread,
fork,
forktry,
await,
-- * Extended API
fork_,
forkWith,
forkWith_,
forktryWith,
Ki.awaitSTM,
Ki.waitSTM,
-- ** Thread options
Ki.ThreadOpts (..),
Ki.defaultThreadOpts,
Ki.ThreadAffinity (..),
-- ** Bytes
Ki.Bytes,
Ki.kilobytes,
Ki.megabytes,
)
where
import Control.Exception (Exception)
import Control.Monad.IO.Class (MonadIO (liftIO))
import Control.Monad.IO.Unlift (MonadUnliftIO (withRunInIO))
import qualified Ki
import Prelude
-- | See 'Ki.await'.
await :: MonadIO m => Ki.Thread a -> m a
await thread =
liftIO (Ki.await thread)
-- | See 'Ki.fork'.
fork :: MonadUnliftIO m => Ki.Scope -> m a -> m (Ki.Thread a)
fork scope action =
withRunInIO \unlift -> Ki.fork scope (unlift action)
-- | See 'Ki.fork_'.
fork_ :: MonadUnliftIO m => Ki.Scope -> m () -> m ()
fork_ scope action =
withRunInIO \unlift -> Ki.fork_ scope (unlift action)
-- | See 'Ki.forkWith'.
forkWith :: MonadUnliftIO m => Ki.Scope -> Ki.ThreadOpts -> m a -> m (Ki.Thread a)
forkWith scope opts action =
withRunInIO \unlift -> Ki.forkWith scope opts (unlift action)
-- | See 'Ki.forkWith_'.
forkWith_ :: MonadUnliftIO m => Ki.Scope -> Ki.ThreadOpts -> m () -> m ()
forkWith_ scope opts action =
withRunInIO \unlift -> Ki.forkWith_ scope opts (unlift action)
-- | See 'Ki.forktry'.
forktry :: forall e m a. (Exception e, MonadUnliftIO m) => Ki.Scope -> m a -> m (Ki.Thread (Either e a))
forktry scope action =
withRunInIO \unlift -> Ki.forktry scope (unlift action)
-- | See 'Ki.forktryWith'.
forktryWith ::
forall e m a.
(Exception e, MonadUnliftIO m) =>
Ki.Scope ->
Ki.ThreadOpts ->
m a ->
m (Ki.Thread (Either e a))
forktryWith scope opts action =
withRunInIO \unlift -> Ki.forktryWith scope opts (unlift action)
-- | See 'Ki.scoped'.
scoped :: MonadUnliftIO m => (Ki.Scope -> m a) -> m a
scoped action =
withRunInIO \unlift -> Ki.scoped \scope -> unlift (action scope)
-- | See 'Ki.wait'.
wait :: MonadIO m => Ki.Scope -> m ()
wait scope =
liftIO (Ki.wait scope)