I was trying to do the following: 1. Read a file from disk 2. Cache the results of the file 3. Use the cache if it's requested again
Everything worked fine unless I read the file multiple times before the first read came back -- in this case, obviously the file would be read from disk multiple times because it's not in cache yet. To get around this problem, I came up with a small implementation of promises -- which I will call a "pseudo-promise" because it doesn't do all the stuff that a promise normally does. My goal was to allow it to be used in combination with normal callback styles. https://gist.github.com/anonymous/4421563620c1cbbf5503 It got a little bit out of order here: promise.js should be the first file you look at -- memoize.js is the implementation of it I used for caching files. Because I wanted to be able to pass the "promise" also be used as a callback, I added the finish method directly to the callback function. In this respect, it works different than a normal "promise" in that you'll pass it to the function you want to use a promise with, instead of having the function return a promise. You can check out promiseTest.js for a simpler example of how it works. Any feedback would be appreciated. -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.