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

Join concurrency guard #433

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Join concurrency guard #433

wants to merge 1 commit into from

Conversation

ChrisEineke
Copy link

This guard ensures that while there is a pending promise for a function, subsequent calls will return the pending promise until the pending promise either rejects or resolves.

@briancavalier
Copy link
Member

Thanks, @ceineke, this seems pretty interesting. Can you describe scenarios in which you've needed/used it?

@ChrisEineke
Copy link
Author

This comes in handy when you have a long-running function that isn't re-entrant and has a lot of side effects on the system.

Let's say you have a long-running method X that is run when you receive two different AMQP messages A and B. When you receive message A, you invoke method X. If you then receive message B while the method runs, you can join the result. Vice versa, when you receive message B, you invoke method X. If you then receive message A while the method runs, you can join the result.

@briancavalier
Copy link
Member

@ceineke Thanks for the explanation. If I understand correctly, the first call to the join-guard will trigger an actual call to underlying guarded function. While that call is inflight, that is until the promise returned by the first call settles, all subsequent calls will return a promise that's equivalent (settles in the same way) to that first one. Am I getting that right?

@briancavalier
Copy link
Member

See my comment about refactoring guard(). Do you think that would help to make the join guard simpler and avoid the sneaky use of the reject channel?

As we work through this, it'd be great to add unit tests and docs as well. We may also have to find a name other than join, since when.join already exists and having two things with the same name will probably be confusing.

@ChrisEineke
Copy link
Author

I agree with your explanations. I can take a look at refactoring guard(), providing unit tests and documentation, and suggest a different name. How about merge?

@briancavalier
Copy link
Member

I can take a look at refactoring guard(), providing unit tests and documentation

Cool, thanks!

How about merge?

I've been trying to think of a short phrase that describes what this guard does. The best I've come up with so far are "memoize while in flight" and "memoize until settled". To me, "merge" doesn't quite capture those phrases. Can you think of alternative short phrases that describe this guard? Maybe they will help us come up with a name.

@ChrisEineke
Copy link
Author

Based on this article, how does autoreset sound?

@briancavalier
Copy link
Member

Thanks. Yeah, autoreset is an interesting name, esp since it has a relationship to semaphores. It (and the article) also made me think of debounce (see http://whatis.techtarget.com/definition/debouncing), which is a common concept with circuits/signals and event programming. Those both seem like good candidates.

Pinging @unscriptable to see if has ideas.

@unscriptable
Copy link
Member

One of the meanings of "enjoin" seems appropriate: "to be performed or adopted". If we're using adjectives, the word "shared" seems like it could lead in the right direction.

"memoize" isn't quite right, unfortunately. :)

What about "coincide", "conform", or "accord" (verb sense)?

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

Successfully merging this pull request may close these issues.

3 participants