-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Lock] add a with helper #24146
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
[Lock] add a with helper #24146
Conversation
Haven't used the locks myself yet, but as it's not in the interface, how will I know this method exists? |
|
Thinking about closing this PR, Don't see a real avantage to use it
vs
WDYT? |
👍 for closing |
The advantage is to remove the freedom of a developer to produce a class of bugs where code never reaches the release() call. There are some developers, like me, who are lazy as shit and don't want to think at all. When I see your API I would probably never think about the consequences not putting the release into finally block. By not even giving me that opportunity, you will make my code a bit more robust. Actually I would even suggest removing acquire and release completely from the public API. Btw. anyone interested in taking over a surprisingly similar named project: php-lock/lock#13 |
I also agree that requiring two calls is more error prone. The same goes for transactions with DBAL: you have both choice for greater flexibility but using the |
+1 that this method is more solid than acquire/release pair. This just needs better name. |
Well, as we cannot add the method in the LockInterface (it would be a BC break), this API is not possible. The helper function would need to be implemented separate (and receiving the LockInterface object and the callable as argument) |
Adding is not a BC break. I suggest, add it and mark the others as deprecated. That should discourage users enough to use them. Then, the others can be removed in some distant new major release. |
Adding a method to an interface is a BC break, given everybody who implements the interface will get a Not sure to understand the point of deprecating all others (methods?) |
Oh, true. Ok, you can't do that without BC breaking.
Removing freedom to enforce more robust client code. The idea of having one method is to help the user not to make the mistake of forgetting a release. If you still leave acquire and release in the API, users will use it and potentially shoot them self. Maybe I'm too drastic as there might well be a use case for having them serperate. |
From a suggestion of symfony/symfony-docs#7866 (comment)