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

naming for mutex.lock/mutex.tryLock #29

Open
bakkot opened this issue Sep 18, 2024 · 3 comments
Open

naming for mutex.lock/mutex.tryLock #29

bakkot opened this issue Sep 18, 2024 · 3 comments

Comments

@bakkot
Copy link

bakkot commented Sep 18, 2024

Swift calls these withLock and withLockIfAvailable, which I think are better names.

I'd kind of expect the mutex to be locked after a call to mutex.lock(...), which it isn't.

And try in JS usually means something to do with exceptions; it's a bit weird to see it used in another context.

@syg
Copy link
Collaborator

syg commented Sep 18, 2024

I'd kind of expect the mutex to be locked after a call to mutex.lock(...), which it isn't.

In case of timeout, you mean? I got confused with what version you're referring to. I think you're referring to the callback-taking version instead of a simple lock/unlock version, or one with a disposable token as you've proposed.

@bakkot
Copy link
Author

bakkot commented Sep 18, 2024

Sorry, yes, referring to the callback-taking version in the readme:

mutex.lock(function runsUnderLock() {
  // Do critical section stuff
});

.lock() is a perfectly reasonable name for the simple lock/unlock version or the one taking a token, but I don't think it makes sense as a name for "run this function after acquiring the lock, then release the lock".

@syg
Copy link
Collaborator

syg commented Sep 18, 2024

I'm writing the spec draft right now and sorely need to update the README, but I'm moving away from the callback taking version to start in favor of either the simple lock/unlock for flexibility in the future with dispose, or the token. I need to noodle on the token thing some more, will reply in the other thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants