@@ -46,16 +46,16 @@ import Control.Monad.Base (MonadBase (..), liftBaseDefault)
4646import Control.Monad.Catch (MonadThrow, throwM)
4747import Control.Monad.State (MonadIO (..), MonadPlus (..),
4848 StateT (..), liftM, runStateT,
49− gets, modify)
49+ modify)
5050import Control.Monad.Trans.Class (MonadTrans (lift))
5151import Control.Monad.Trans.Control (ComposeSt, MonadBaseControl (..),
5252 MonadTransControl (..),
5353 defaultLiftBaseWith,
5454 defaultRestoreM, liftBaseWith)
55+import Data.IORef (newIORef, readIORef, writeIORef)
5556import Unsafe.Coerce (unsafeCoerce)
5657
5758import Control.Monad.Trans.Recorder (MonadRecorder(..))
58−import Data.IORef (newIORef, readIORef, writeIORef)
5959--import Debug.Trace (traceM)
6060
6161import Asyncly.Threads
@@ -287,18 +287,8 @@ makeAsync = AsyncT . makeCont
287287-- Controlling thread quota
288288------------------------------------------------------------------------------
289289
290−-- XXX Should n be Word32 instead?
291290-- | Runs a computation under a given thread limit. A limit of 0 means all new
292291-- tasks start synchronously in the current thread unless overridden by
293292-- 'async'.
294293threads :: MonadAsync m => Int -> AsyncT m a -> AsyncT m a
295−threads n process = AsyncT $ do
296− oldCr <- gets threadCredit
297− newCr <- liftIO $ newIORef n
298− modify $ \s -> s { threadCredit = newCr }
299− r <- runAsyncT $ process
300− >>* (AsyncT $ do
301− modify $ \s -> s { threadCredit = oldCr }
302− return (Just ())
303− ) -- restore old credit
304− return r
294+threads n action = AsyncT $ threadCtl n (runAsyncT action)