-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Introduce SingleFlight (function de-duplication) #2470
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
Comments
Memoization is not strictly related to coroutine, so why you should put it here instead of in a third party library? |
Hmm. I'll need to look into Memorization more but i believe the difference between single flight and that is that single flight only applies to things that are in progress. So I don't know it's really considered a cache. |
On the surface, this seems to be an interesting coroutine-related primitive to have in the library (it is not a cache and is indeed very coroutine-specific), but it will definitely require a non-trivial design effort to get a composable and minimal API here. However, I do have a feeling that having just an "in-flight deduplication" supported will be clearly not enough. People will immediately want "to keep this key for a few more seconds after the answer", "to limit the number of such kept entries", etc, and it will end up with a full-blown cache implementation with tons of configuration options. This definitely deserves a separate library for now. We will not have the resources to engage in such an extensive design effort in the near future as we have quite a number of core concerns to cater for. |
|
This is to resolve #1097. I have a local branch right now testing this out, but wanted to submit this issue to talk about the design. Essentially, we want to have the same functionality as SingleFlight from Go. The idea is that if you have a function A with a certain key in flight and another function B with the same key comes, function B will get function A's result.
Here's how I picture the public API for coroutines:
And here's how it would be used:
Hopefully that all makes sense. One question I've been dating is how to handle exceptions. If there's an exception within the block function... how should we handle it? My first thought is to just let it bubble up. The original Go API provides exception with the result if I'm not mistaken. We could go that route also.
The text was updated successfully, but these errors were encountered: