How can I memoize a promise-based function?
Would straightforward memoization of the function suffice?
function foo() {
return new Promise((resolve, reject) => {
doSomethingAsync({ success: resolve, fail: reject });
});
};
Would this suffice?
var fooMemoized = memoize(foo);
Note: this question has been updated to remove the deferred anti-pattern.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…