medikoo / memoizee

Complete memoize/cache solution for JavaScript
ISC License
1.73k stars 61 forks source link

Improve 'promise' mode with `thenInjection` option #60

Open medikoo opened 8 years ago

medikoo commented 8 years ago

/cc @Kovensky

If used implementation doesn't implement done and finally then it's not possible to do both:

The workaround could be, to provide a special mode for promise handling, in which user will agree that memoized function will return extended promise from original and not exactly one returned by original function.

Rush commented 8 years ago

I just suffered from memoizee using the .done and me using Bluebird. Bluebird will do process.exit inside .done. http://bluebirdjs.com/docs/api/done.html "any unhandled rejection that ends up here will crash the process (in node)"

With bluebird one can use http://bluebirdjs.com/docs/api/reflect.html in order to find the resolved value without side effects.

Above was a reply to https://github.com/medikoo/memoizee/pull/59#issuecomment-232275536

medikoo commented 8 years ago

@Rush Just setup memoization with promise: 'then' option, and it'll be fine. It's documented: https://github.com/medikoo/memoizee#promise-returning-functions

medikoo commented 7 years ago

@Rush I've improved internal handling, so now by default when using Bluebird then:finally mode will be used. done mode is not recommended (and since v0.4.7 not applied by default) for reasons you mentioned (unconditional crashing in case of rejections)

Rush commented 7 years ago

@medikoo thank you! exciting