-
-
Notifications
You must be signed in to change notification settings - Fork 25
Add lock function #34
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
Conversation
| StatCache::clear($file); | ||
| } | ||
| $operation |= LOCK_NB; | ||
| $res = \fopen($file, 'c'); |
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.
Shouldn't we just open the file here instead of the additional touch above?
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.
Well technically yes, but then the touching wouldn't be async.
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.
Well, the fopen isn't async anyway? I guess we'd have to add the function to Handle to have it really async?
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.
Well, fopen isn't async, but afaik there is no way to obtain a lock using any of the native async libs supported by amphp.
I thought it'd be nice if we could make at least the touch part of the fopen async.
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.
@trowski What's your opinion here?
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 rather uncomfortable introducing anything that can block when it could be rolled into a simple Task executed using parallel.
|
|
||
| while (!\flock($res, $operation, $wouldblock)) { | ||
| if (!$wouldblock) { | ||
| throw new FilesystemException("Failed acquiring lock on file."); |
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.
Should we check for the file being deleted here and recreate it? I guess it could make sense to delete after unlocking, but not in every case (i.e. only if it's a separate lock file).
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 really don't think this is the place for such logic
|
Superseded by #87. |
No description provided.