@@ -29,7 +29,6 @@ module Asyncly.Core
2929 , SVarSched (..)
3030 , SVarTag (..)
3131 , SVarStyle (..)
32− , EndOfStream (..)
3332 , newEmptySVar
3433 , newStreamVar1
3534 , newStreamVar2
@@ -48,7 +47,7 @@ import Control.Concurrent (ThreadId, forkIO,
4847 myThreadId, threadDelay)
4948import Control.Concurrent.MVar (MVar, newEmptyMVar, tryTakeMVar,
5049 tryPutMVar, takeMVar)
51−import Control.Exception (SomeException (..), Exception)
50+import Control.Exception (SomeException (..))
5251import qualified Control.Exception.Lifted as EL
5352import Control.Monad (MonadPlus(..), mzero, when)
5453import Control.Monad.Base (MonadBase (..), liftBaseDefault)
@@ -321,10 +320,6 @@ sendWorkerWait sv = do
321320 then (pushWorker sv) >> sendWorkerWait sv
322321 else void (liftIO $ takeMVar (doorBell sv))
323322
324−-- | A stream being pulled from 'SVar' has ended.
325−data EndOfStream = EndOfStream deriving Show
326−instance Exception EndOfStream
327−
328323-- | Pull a stream from an SVar.
329324{-# NOINLINE fromStreamVar #-}
330325fromStreamVar :: MonadAsync m => SVar m a -> Stream m a
@@ -332,15 +327,16 @@ fromStreamVar sv = Stream $ \_ stp yld -> do
332327 -- XXX if reading the IORef is costly we can use a flag in the SVar to
333328 -- indicate we are done.
334329 done <- allThreadsDone sv
335− when done $ throwM EndOfStream
336−
337− res <- liftIO $ tryTakeMVar (doorBell sv)
338− when (isNothing res) $ sendWorkerWait sv
339− list <- liftIO $ atomicModifyIORefCAS (outputQueue sv) $ \x -> ([], x)
340− -- To avoid lock overhead we read all events at once instead of reading one
341− -- at a time. We just reverse the list to process the events in the order
342− -- they arrived. Maybe we can use a queue instead?
343− (runStream $ processEvents (reverse list)) Nothing stp yld
330+ if done
331+ then stp
332+ else do
333+ res <- liftIO $ tryTakeMVar (doorBell sv)
334+ when (isNothing res) $ sendWorkerWait sv
335+ list <- liftIO $ atomicModifyIORefCAS (outputQueue sv) $ \x -> ([], x)
336+ -- To avoid lock overhead we read all events at once instead of reading
337+ -- one at a time. We just reverse the list to process the events in the
338+ -- order they arrived. Maybe we can use a queue instead?
339+ (runStream $ processEvents (reverse list)) Nothing stp yld
344340
345341 where
346342