Change (some) callbacks to only trigger when complete. #23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a proof-of-concept PR for the issue raised in #22. In particular, the caller-provided callback is only called when all of the cache modules have completed.
In making this change, I discovered several other issues that should probably be addressed.
In general the cache-service "writing" APIs (
.set()
,.mset()
,.del()
, and.flush()
) don't define what the caller-provided callback will be passed on success, failure, or partial failure. (I suspect cache-service will need to define something like an "aggregate error" to encapsulate the "one or more modules had a problem" scenario.)The
.get()
API implies (by "response... null on cache miss") that a cache miss should not pass an error value to the callback; this should likely be explicit. On the other hand, cache-service's implementation handles module.get()
errors by simply trying the next module, so perhaps cache-misses should be handled by an error value, allowing any value (including null and undefined) for a cache-hit.The module API doesn't specify what should be passed to the callback on success or failure. Is only the
err
argument used? Is nothing inspected, and the callback used only to indicate completion?