-
Notifications
You must be signed in to change notification settings - Fork 54
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
Wrap callbacks in newtype to make wrong usage harder #161
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great idea, thank you for this PR!
I put some comments where I think we can improve the API.
Other than that, I am 100% onboard with these changes (though I'm not the project owner so I can't merge it 😄 )
where | ||
realCb k err pl = do | ||
realCb kc k err pl = do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark
where | ||
realCb k err pl = do | ||
realCb kc k err pl = do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why you also renamed this variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue here is that because the KafkaConf
argument moves into the newtype, the variable is now bound in the lambda instead of the function definition:
Callback $ \kc@(KafkaConf con _ _) -> rdKafkaConfSetRebalanceCb con (realCb kc)
This means kc
is no longer available in the where-clause, hence I added it as an extra argument to realCb
. The other obvious alternative would be to move realCb
into a let
, but I am not sure that is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My apologies, I misread, I thought k
was renamed to kc
but it's another argument
0368fe0
to
2a29065
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
@AlexeyRaga what do you think? Keep in mind this is a breaking change, so this should probably be documented somewhere (like a changelog) to help users migrate
Thanks guys, I will review it soon! |
Looks good to me! Thanks @phile314, I like it! 👍 If you could rebase (I merged a couple of your other PRs) and resolve conflicts then we can hit the green button and make a release! |
Rebased on current master. And thanks already for making a release with these changes, it is greatly appreciated 👍 |
Fix delivery callback (fallout from #161)
I was at first struggling to use the callbacks correctly. Granted, this was mostly my fault as I looked at the wrong hackage version of hw-client which did not yet have the examples in the doc on how to use the callbacks. But anyway, I find having the
... -> k -> IO ()
in the type signature a bit confusing. I was basically doing:instead of using
setCallback
and the producer properties.I think just wrapping the callbacks in a newtype makes it hard (impossible?) to make this mistake and improves readability. What do you think?
PS: Backward-compatiblity is only affected if people gave explicity type signatures for any variable containing the callback. If one just directly passes the callback to
setCallback
no change is required. E.g.:stil compiles.