New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passthroughSink misses last value? #304

Closed
AlexeyRaga opened this Issue Apr 3, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@AlexeyRaga

AlexeyRaga commented Apr 3, 2017

I have the following program:

printSink :: (MonadIO m, Show a) => Sink a m ()
printSink = awaitForever $ \x -> liftIO (print x)

main :: IO ()
main = do
   res <- runConduit $ inputStream .| passthroughSink (printSink) (const $ return ()) .| L.take 5
   print res

It looks like the last value is never passed into a sink inside passthroughSink:

("a1","a1")
("a2","a2")
("a3","a3")
("b1","b1")
[("a1","a1"),("a2","a2"),("a3","a3"),("b1","b1"),("b2","b2")]

First 4 lines are prints from within printSink, the last one is from main and it contains all 5 elements as expected.

Is it a bug or I am doing something wrong?

snoyberg added a commit that referenced this issue Apr 3, 2017

Same inputs provided in passthroughSink #304
Ensure downstream and inner sink receive same inputs, see lengthy
comment added to code for explanation
@snoyberg

This comment has been minimized.

Show comment
Hide comment
@snoyberg

snoyberg Apr 3, 2017

Owner

Very nice catch! The bug is pretty tricky, I've added a lengthy comment in my commit. Can you review, try out the code, and let me know if it fixes your issue?

Owner

snoyberg commented Apr 3, 2017

Very nice catch! The bug is pretty tricky, I've added a lengthy comment in my commit. Can you review, try out the code, and let me know if it fixes your issue?

@AlexeyRaga

This comment has been minimized.

Show comment
Hide comment
@AlexeyRaga

AlexeyRaga Apr 3, 2017

I read the comments and it looks good to me, thanks for an explanation!
It also answers another question I had in my mind: whether yield to downstream happens before or after the value is passed through the sink.
In some situations, it is important that the sink "sees" the value first and the downstream second, as far as I understand, it is what happens now.
Thanks again for a quick response and a fix!

AlexeyRaga commented Apr 3, 2017

I read the comments and it looks good to me, thanks for an explanation!
It also answers another question I had in my mind: whether yield to downstream happens before or after the value is passed through the sink.
In some situations, it is important that the sink "sees" the value first and the downstream second, as far as I understand, it is what happens now.
Thanks again for a quick response and a fix!

@snoyberg

This comment has been minimized.

Show comment
Hide comment
@snoyberg

snoyberg Apr 4, 2017

Owner

Thanks for the report and the quick response, new version is on Hackage.

Owner

snoyberg commented Apr 4, 2017

Thanks for the report and the quick response, new version is on Hackage.

@snoyberg snoyberg closed this Apr 4, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment