-
Notifications
You must be signed in to change notification settings - Fork 87
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
Refactor client reset #1003
Refactor client reset #1003
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.
Have a few suggestions in the c++ part, but otherwise fine with me
Co-authored-by: Kasper Overgård Nielsen <kasper.nielsen@mongodb.com>
Co-authored-by: Kasper Overgård Nielsen <kasper.nielsen@mongodb.com>
RLM_API void realm_dart_invoke_unlock_callback(bool success, void* unlockFunc) | ||
{ | ||
auto castFunc = (reinterpret_cast<realm::util::UniqueFunction<void(bool)>*>(unlockFunc)); | ||
(*castFunc)(success); | ||
} |
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.
I dislike that this is now so specific. There's nothing in the function implementation that indicates that this is somehow related to locking. It's just invoking a function that takes a boolean. The fact that in the client reset flow it'll unlock a lock is an implementation detail.
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 exactly a specific function to unlock and the argument is called unlockFunc, hence the otherway around was weird. This makes it more clear what it does and when it should be used.
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.
I think we can renamed only the argument name. It has left unchanged after I refactored the function to be general.
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.
No, I very strongly disagree. We don't need and we are not trying to write a generic function that can invoke arbitrary functions that take a boolean in native code. We don't have such use case at hand. We are trying to provide a specific mechanism that when needed, can call Dart and wait for a result synchronously and needs an unlock function to continue. This unlock can be used for any generic case where we need a result from dart through the Scheduler.
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.
I also think we should rename the argument - it's a void* which is then cast to function(bool)
. Nothing about it deals with unlocking anything.
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.
@nikola This function is named after what it does and not how it is used. It invokes a unlock function callback which was passed to a Dart function which accepts a unlock callback argument. This ties the whole concept together. So later when someone needs to do the same it is obvious what needs to be done. create a static dart function which should return a result using that function and continue the operation
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.
Again, the function being passed as an argument is not an unlock function. It's a function(bool).
The fact it's an unlock function is controlled from the outside. So you're naming this function after how it's being consumed.
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.
Consider this extreme example:
void bark(Object dog) {
final animal = dog as Animal;
animal.produceSound();
}
final dog = Dog();
dog.bark();
Do you think the bark function is named correctly here? Because this is what is essentially happening with this C function. We accept a generic void* pointer, we cast it to a function(bool), then invoke that function. And we call the argument unlockFunc
because we expect that consumers are going to invoke us with a function that unlocks something.
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.
I don't think we are getting anywhere here. I would like to move away from bike shading the function name. The function is called invoke_unlock_callback
and it does what it says and expect a specific argument to be passed in and be used in a specific case. Lets move the discussion to another place where we can gain more value.
The other feedback for deadlocks is more important in this PR. I am trying to handle it.
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.
I'm fine with moving the discussion elsewhere, but I disagree with changing the function name here. Since both Desi and I believe the old name is better and the name change is not fixing an actual bug, let's keep the original name and we can rename it once we've completed bikeshedding.
release unowned realms
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 once we revert the function name change :)
refactor client reset