on master help sign in
Simplify toList runner
commit9f7d6724226993c3e9c725bd6c39add2d2401093 authorHarendra Kumar <harendra.kumar@gmail.com> dateFri 11 Aug 2017, 13:36 (9 years ago) parentc9b9ab3
1 file changed+10−13
src/Asyncly/RunAsync.hs+10−13
src/Asyncly/RunAsync.hs+10−13
@@ -92,8 +92,9 @@ runAsynclyLogged lref m = do
9292 where
9393
9494 stop = return ()
95− run ct mx = (runAsyncT mx) ct stop (\_ ct r ->
96− maybe stop (\x -> (run ct x)) r)
95+ {-# INLINE yield #-}
96+ yield _ c r = maybe stop (\x -> (run c x)) r
97+ run ct mx = (runAsyncT mx) ct stop yield
9798
9899runAsyncly :: MonadAsync m => AsynclyT m a -> m ()
99100runAsyncly m = runAsynclyLogged Nothing m
@@ -110,17 +111,13 @@ toList m = do
110111
111112 where
112113
113− stop = return Stop
114− done a = return (Done a)
115− yield a c x = return $ Yield a c x
116−
117− run ctx ma = do
118− res <- (runAsyncT ma) ctx stop (\a c r ->
119− maybe (done a) (\x -> yield a c x) r)
120− case res of
121− Yield x c mb -> liftM (x :) (run c mb)
122− Stop -> return []
123− Done x -> return (x : [])
114+ stop = return []
115+ done a = return [a]
116+ {-# INLINE yield #-}
117+ yield a c r = maybe (done a) (\x -> liftM (a :) (run c x)) r
118+
119+ {-# INLINE run #-}
120+ run ctx mx = (runAsyncT mx) ctx stop yield
124121
125122{-# INLINABLE each #-}
126123each :: MonadAsync m => [a] -> AsynclyT m a