on master help sign in
Simplify toList runner
9f7d672Harendra Kumar
src/Asyncly/RunAsync.hs+10−13
@@ -92,8 +92,9 @@ runAsynclyLogged lref m = do
92 where
92 where
93
93
94 stop = return ()
94 stop = return ()
95− run ct mx = (runAsyncT mx) ct stop (\_ ct r ->
95+ {-# INLINE yield #-}
96− maybe stop (\x -> (run ct x)) r)
96+ yield _ c r = maybe stop (\x -> (run c x)) r
97+ run ct mx = (runAsyncT mx) ct stop yield
97
98
98runAsyncly :: MonadAsync m => AsynclyT m a -> m ()
99runAsyncly :: MonadAsync m => AsynclyT m a -> m ()
99runAsyncly m = runAsynclyLogged Nothing m
100runAsyncly m = runAsynclyLogged Nothing m
@@ -110,17 +111,13 @@ toList m = do
110
111
111 where
112 where
112
113
113− stop = return Stop
114+ stop = return []
114− done a = return (Done a)
115+ done a = return [a]
115− yield a c x = return $ Yield a c x
116+ {-# INLINE yield #-}
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)
117+ yield a c r = maybe (done a) (\x -> liftM (a :) (run c x)) r
120− case res of
118+
121− Yield x c mb -> liftM (x :) (run c mb)
119+ {-# INLINE run #-}
122− Stop -> return []
120+ run ctx mx = (runAsyncT mx) ctx stop yield
123− Done x -> return (x : [])
124
121
125{-# INLINABLE each #-}
122{-# INLINABLE each #-}
126each :: MonadAsync m => [a] -> AsynclyT m a
123each :: MonadAsync m => [a] -> AsynclyT m a