Anyone have any suggestions? Naming of .finish to something else? Would
anyone use this if I published it? I thought the most useful part of it is
that it can interop with regular callback style.
On Monday, April 1, 2013 1:10:28 PM UTC-4, Paul wrote:
>
> Btw, you also CAN return the promise from the function you call:
>
> function doSomethingElse(callback){
> var p = promise(callback);
> setTimeout(function(){
> p(1,2);
> }, 1000);
> return p;
> }
>
> var p = doSomethingElse();
> p.finish(function(a,b) { console.log(a, b); });
>
> On Monday, April 1, 2013 11:14:07 AM UTC-4, Paul wrote:
>>
>> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.