on master help sign in
Fix scheduling of WAsync style stream

We were scheduling it in the same manner as Async, instead we have to schedule the actions from the two streams in a round robin fashion. Fixes #371

commit3f5c79ea949da479fcbb9f10b197c5998c927086 authorHarendra Kumar <harendra.kumar@gmail.com> dateThu 16 Jan 2020, 23:29 (7 years ago) parentd35674e
2 files changed+9−7
Changelog.md+1 src/Streamly/Internal/Data/Stream/Async.hs+8−7
Changelog.md+1
@@ -11,6 +11,7 @@
1111 stream, especially when built with `-threaded` and used with `-N` RTS option.
1212 The issue occurs only in cases when a worker thread happens to be used
1313 continuously for a long time.
14+* Fix scheduling of WAsyncT stream style to be in round-robin fashion.
1415
1516### Behavior change
1617
src/Streamly/Internal/Data/Stream/Async.hs+8−7
@@ -225,13 +225,14 @@ workLoopFIFO q st sv winfo = run
225225 res <- liftIO $ sendYield sv winfo (ChildYield a)
226226 return $ if res then Continue else Suspend
227227
228+ -- XXX in general we would like to yield "n" elements from a single stream
229+ -- before moving on to the next. Single element granularity could be too
230+ -- expensive in certain cases. Similarly, we can use time limit for
231+ -- yielding.
228232 yieldk a r = do
229233 res <- liftIO $ sendYield sv winfo (ChildYield a)
230− if res
231− then foldStreamShared st yieldk single (return Continue) r
232− else liftIO $ do
233− enqueueFIFO sv q r
234− return Suspend
234+ liftIO $ enqueueFIFO sv q r
235+ return $ if res then Continue else Suspend
235236
236237{-# INLINE workLoopFIFOLimited #-}
237238workLoopFIFOLimited
@@ -273,12 +274,12 @@ workLoopFIFOLimited q st sv winfo = run
273274
274275 yieldk a r = do
275276 res <- liftIO $ sendYield sv winfo (ChildYield a)
277+ liftIO $ enqueueFIFO sv q r
276278 yieldLimitOk <- liftIO $ decrementYieldLimit sv
277279 if res && yieldLimitOk
278− then foldStreamShared st yieldk single incrContinue r
280+ then return Continue
279281 else liftIO $ do
280282 incrementYieldLimit sv
281− enqueueFIFO sv q r
282283 return Suspend
283284
284285-------------------------------------------------------------------------------