Memoization of promise-based function

Yes, that will suffice. Promises are simple return values, which is their great benefit – in contrast to callbacks, where memoisation code would be horrible.

You only might want to make sure that the memoized promise is uncancellable, if your promise library does support some kind of cancellation. Also notice that this form of memoisation remembers rejections as well, so you can’t recover from errors by “trying again”.

Leave a Comment