-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
Introduce 'promise' mode #35
Conversation
+1 could definitely use this! |
+1. Here's a temporary workaround I'm using ( function doMemoizeFunction(func, options)
{
let memoized = memoize(arity(options.length || func.length,
function(...args)
{
let result = func.apply(this, args);
if (result && typeof result.then == "function")
{
result.then(null, () => memoized.delete(...args));
}
return result;
}), options);
return memoized;
} |
Other workaround, can look as: var memoized = memoize(function () {
var context = this, args = arguments;
return returnsPromise.apply(context, args).then(null, function (err) {
memoized.delete.apply(context, args);
throw err;
});
}, { length: returnsPromise.length }); Still it's not ideal when combined with other options as |
I have a couple of strange question:
|
@puzrin indeed your questions are not clear to me. Answering best I could:
|
I considered, does it worth to create separate package for promises with my own efforts. Seems, that will have almost no advantages (+ additional time spends for maintenance). |
@puzrin you can introduce external extensions, e.g. that way: // Configure new extension
var myExtension = function (myExtensionOptions, memoizedFunctionData, memoizeOptions) {
...
};
require('memoizee/lib/registered-extensions').myExtension = myExtension;
// Memoize function and use provided extension
var fn = function (...) {...}
var memoizedFn = memoize(fn, { myExtension: myExtensionOptions }) Just be sure to not use |
https://github.com/nodeca/promise-memoize did a separate simple package. No weakmaps, no lru, no stat... but it works :). Also does not drop cache on prefetch and unref timers. |
Great if that works for you, and sorry that I couldn't handle that one earlier |
That way we do not mark eventual error as handled
So they're not immune to race conditions
Still allow to force `then` usage with implementations that have primitive `done` support
Published with v0.4.0 |
At this point promise returning functions are memoized natural way, which seems ok, but there's one flaw, Rejected promise results are treated same as successful ones, that's not right.
We should not store them, same way as we do not store sync function crashes, or errors in async mode.