Add Promise support
See original GitHub issueWorking on a version of this on my fork now but it would be great to be able to pass in a promise and have the library return a promise that resolved to that result.
ie:
var foo = memoize(myPromiseReturningFunc);
foo(a, b, c).then((data) => {
// do something with the data...
});
Per JS spec the official way of doing this check would be typeof fn.then == "function"
as that makes the function a “thenable”.
Thoughts, concerns, etc? I may open a PR if I get it in fast enough 😉
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:17 (7 by maintainers)
Top Results From Across the Web
Promise - JavaScript - MDN Web Docs
A Promise is a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers with...
Read more >Adding Promise Support to a Node.js Library - Brian Cline
There are a few different ways to convert callbacks to use promises. In the built-in util package, there's a function called promisify() that ......
Read more >Native Support for Promises in Node.js - Stack Overflow
Node.js added native promise support since version 0.11.13 . nvm install 0.11.12 nvm run 0.11.12 > Promise ReferenceError: Promise is not defined ...
Read more >Callback and Promise Support in your Node.js Modules
Lift your modules and applications to the next level by supporting promises besides callbacks. Developers out there will thank you for that move ......
Read more >JavaScript Promises - W3Schools
The Promise object supports two properties: state and result. ... Both are optional, so you can add a callback for success or failure...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
BTW, let’s work together on the next major version =)
Will create a document and share with you Once we are happy with the architecture, we can start coding
The main idea is to give a function with as less checking as possible based on hints given by user If user don’t give any hint, we have to use a generic function
Here’s a workaround with the current library (in typescript). Half to help out and half for peer review in case I missed something. The serializer seems to assume a string hash, but I needed access to the arguments for the retry case, so it requires a little bit of a hack.