Skip to content
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

Add lock function #34

Open
wants to merge 5 commits into
base: 2.x
Choose a base branch
from
Open

Add lock function #34

wants to merge 5 commits into from

Conversation

danog
Copy link
Contributor

@danog danog commented Jul 15, 2019

No description provided.

lib/functions.php Outdated Show resolved Hide resolved
test/HandleTest.php Outdated Show resolved Hide resolved
test/HandleTest.php Outdated Show resolved Hide resolved
lib/functions.php Outdated Show resolved Hide resolved
StatCache::clear($file);
}
$operation |= LOCK_NB;
$res = \fopen($file, 'c');
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Member

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.

lib/functions.php Outdated Show resolved Hide resolved

while (!\flock($res, $operation, $wouldblock)) {
if (!$wouldblock) {
throw new FilesystemException("Failed acquiring lock on file.");
Copy link
Member

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).

Copy link
Contributor Author

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

lib/functions.php Outdated Show resolved Hide resolved
lib/functions.php Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants