Join concurrency guard#433
Join concurrency guard#433ChrisEineke wants to merge 1 commit intocujojs:masterfrom ChrisEineke:guards
Conversation
|
Thanks, @ceineke, this seems pretty interesting. Can you describe scenarios in which you've needed/used it? |
|
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. |
|
@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? |
|
See my comment about refactoring 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 |
|
I agree with your explanations. I can take a look at refactoring |
Cool, thanks!
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. |
|
Based on this article, how does |
|
Thanks. Yeah, Pinging @unscriptable to see if has ideas. |
|
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)? |
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.