I'm really interested in implementing Promises and related features in client-side Javascript. From what I've seen, the focus in implementing these technologies in Javascript seems to be on server-side javascript (SSJS) with Promises in CommonJS . Ideally for me, I would find a solution that works well with jQuery or Google Closure Library, but I'm open to any solution.
- Is it possible to use the CommonJS solution client-side? This Sitepen article has some great information on promises in CommonJS, but it is focused on SSJS.
- What other libraries are available that implement promises that can easily work client-side?
- What are your impressions, experience, and feedback on any toolkit you have used?
I've found a few client-side implementations, but I'm unclear on how robust they are. Is there any library that has become the de-facto standard? Is a mainstream library (like jquery) already working on something similar for a future release?
-
MSDN library has an implementation of promises and futures
- An implementation is on github and described in this article - this one looks pretty good
- Dojo has a feature called Deferreds , but the Sitepen article points out flaws
- Douglas Crockford talks about Promises , but I can't locate his implementation
Any others? Anyone have experience with any of these and have a preference? Is one better than the others?
Source: Tips4all
I'm the developer of FutureJS - JavaScript's Async Toolbox TM (or at least that's the goal).
ReplyDeleteDocs v2.x (obsolete v1.x)
Development
Production - < 3K minified and gzipped
I started with the snippets from
Crockford's slides. Here's the original & unadultered implementation.
As I've run into more issues and have seen what others have done I continue to update the library with best-practice solutions.
If CommonJS ever makes an official standardization, I'd consider releasing a v3.x that caters to that, but currently Futures is fairly simple and does what it is designed to do.
I'd love to have you join the mailing list and give me your feedback and suggestions.
Other features of the library include:
asyncify
chainify
future
join
loop
sequence
forEachAsync
Each submodule can be easily installed or packaged on it's own
npm install future join
ender build future join
=8^D
P.S. FuturesJS will work alongside jQuery, Underscore.js, etc, in both Node.js and Ender.js. There are no dependencies. I believe that it will work with Rhino as well. If not, let me know and it should be a quick fix.
P.P.S. InfoQ has an article on several js async toolkits
http://www.sitepen.com/blog/2010/05/03/robust-promises-with-dojo-deferred-1-5/ should answer your question exactly
ReplyDeleteKris Kowal's Q module can be used on the client side. It works with RequireJS, and it conforms to CommonJS/Promises/A, B, and D.
ReplyDeleteI haven't compared it to other implementations, but I use it, I like it, and it works for me.
Also, see the following on StackOverflow:
ReplyDeleteDo any IDEs/IDE plugins have support for JavaScript CommonJS modules?