On Sun, Mar 27, 2011 at 11:47 AM, Mark McDonnell <[email protected]>wrote:

> Hi,
>
> I've been searching for an article to explain how to implement
> Promises/Defers/When/Then functionality but all I seem to find are articles
> based on how to use client/sever-side js libraries that already implement
> it.
>
> I have found a couple of Promise examples via Github gusts but they are
> extremely 'bare boned' and also don't explain how you could use them and for
> someone like me I learn better through working examples.
>

Why do you need to implement when there are so many implementations already?
In any event, here's Kris Zyp's (the author of the standard) implementation
of Promises/A [1]. And Kris Kowal's robust implementation [2] -- I think it
was originally Promises/B but now supports thenables as well, and is
compatible with Promises/A "thenable" promises like what's in dojo and such.

[1] https://github.com/kriszyp/promised-io/blob/master/lib/promise.js
[2] https://github.com/kriskowal/q/blob/master/lib/q.js


>
> Any help would be really appreciated!
>

Can you be more specific? Are you looking to implement a new lib or just
learn what they're all about? The "thenable" interface is pretty easy to
wrap your head around -- somePromise.then(callback, errback) -- that's all
there is to it.

Of course, every good promise lib has a "when" function --
when(possiblePromise, callback, errback) -- note the similarities to then's
signature, except it can be provided non-promises as well. There's really
not much to it, which is kinda the point. From there you can build other
useful control flow helpers.

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to