Click here to Skip to main content
15,902,635 members
Articles / All Topics

Using Q Promise Library to Handle Async Functions on Array Contexts

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
6 Nov 2013CPOL 6.9K   1  
Using Q Promise Library to Handle Async Functions on Array Contexts

No more JQuery Deferred for me. From now on, I'm using a Promise Library that allows me more powerful operations like chaining and combinations.

In this post, I'm focusing on array operations like:

  1. Execute multiple functions and execute something after all of these have finished
  2. Map() implementation using async functions (aka: qMap)

Each of the points above are available on jsFiddle for you to tweak...

Using Q.all, we can achieve this easily. Just take a peak at this jsFiddle.

To execute async functions in sequence over an array of items, the qMap function was created. The signature of this is the same as the map() but the difference is that each function return a Q.promise to sync the execution. Check this jsFiddle.

Unfortunately, I could not find any other way, using Q, to achieve this sync execution so I've written the qMap function. If you find any other way to write this, please let me know.

Links

This article was originally posted at http://blog.divhide.com/feeds/posts/default

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Portugal Portugal
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --