Implementing a Single Refresh with Effect Primitives

What Effect primitives would I want to use for this:

I store value x in some ExternalStore
I have an effect ensureValueFreshness that checks if that value is "stale", and if so, requests a fresh value from an external service and write the new value to the store.
I have another effect getFreshValue that returns the current value if it is fresh, if it's stale, it triggers a refresh, returning the new value.

I want to be able to call getFreshValue many times, with only a single refresh happening, and all subsequent requests waiting for the result of the pending refresh
Was this page helpful?