-
Notifications
You must be signed in to change notification settings - Fork 215
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
Callback invoker to sink all thrown exceptions #74
Conversation
include/cppkafka/callback_invoker.h
Outdated
class CallbackInvoker; | ||
|
||
template <typename RetType, typename ...Args> | ||
class CallbackInvoker<RetType(Args...)> |
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.
Wouldn't it be better to use a simple function instead of this? I don't think there should be a need to indicate all template parameters when instantiating this, especially since this is always used internally. Something like this would work:
template <typename RetType, typename Callback, typename... Args>
RetType safe_invoke_callback(const std::string& callback_name,
const Callback& callback,
KafkaHandleBase* handle,
Args&&... args);
Which you can just invoke by doing:
safe_invoke_callback<int32_t>(callback_name, callback, nullptr,
topic, key, partition_count);
I exposed the args because initially i was going to replace all the callback members with this wrapper so I wanted it to behave as much as possible as
Perhaps a good compromise would be:
Also I have a question for you. If the callback throws, the callback functor (or free function) will return
Returning
and in cases like the buffered_producer in the
|
507a135
to
ca17d44
Compare
@mfontanini btw, on a totally unrelated tangent, I am never able to link the test application w/o using
I don't want to check this in, in case it may break other people's build but I wonder if I'm the only one with this issue. These are dependencies from librdkafka which I'm sure could be removed with compile time options, but what if other people need to use them? In that case your code does not link. I think having these will allow more flexibility for different compile settings that people might have. |
Your arguments are usually very strawman-ish :). If you want to add a new parameter... you add it and then your compiler will complain because you're trying to call the callback with N+1 instead of N parameters. You go there and you fix it. This is an internal function so you know what you're doing. You'd have to change all invocations of the constructor in your case as well. Anyway, I'm fine with just taking the callback and forwarding the parameters as you posted on your comment. I just don't think it's worth explicitly using all parameters and that fixes it so it's okay. Regarding tests, this is probably how librdkakfa gets built where it uses features if it can basically. We can fix that. It will break on Windows but as it is now it's trying to link with |
That also works in relationships btw :). Ok, wrt the callback. I'll keep the middle compromise proposal since I have most of the code as-is. |
I'm not entirely sure why that happens. This also works fine in travis so it's not just my setup. I'm not sure how rdkafka decides to depend on libraries. Anyway, those sound like good defaults which everyone should have (at least in linux/osx). |
29d0635
to
332beb1
Compare
332beb1
to
3552e9b
Compare
include/cppkafka/callback_invoker.h
Outdated
@@ -0,0 +1,127 @@ | |||
/* |
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.
Sorry, one last thing: can you move this inside include/cppkafka/detail
? That's probably a better location for it, given this should only be used internally as a helper.
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.
done!
Provide a way to consistently invoke all callbacks which run on the librdkafka stack and prevent them from throwing. An error will be logged accordingly if a log callback is passed. Log callback is also guarded for throws.