The pattern I've used for this problem is queueing - you pass a callback
into a long running method, the method returns immediately, and queues the
callback to be executed when it's done.

 The interface allows for any number of calls to the long running process -
if it's not done, callbacks would just queue up and be executed in order at
some point later. I can see promises being a nice abstraction for this type
of manual control flow.

- Anatoly

On Oct 29, 2011, at 9:20 AM, Mark McDonnell <[email protected]> wrote:

Promises/Deferreds are great for anything asynchronous.

For example if I call a function that processes a large array then I'll use
a timer to chunk the array so as not to lock up the UI but timers are async
so the function would return immediately. If I use Promises then it doesn't
matter because I can resolve() the data whenever it's ready.


On 29 Oct 2011, at 10:51, Rob Griffiths <[email protected]> wrote:

 Actually I'm currently working on a node project and I've already hit the
dreaded nesting. Everything is callbacks. Im definatly seeing the benefits
for promises.

I'd love to see some examples of promises being passed around in preference
to callbacks.

-- 
Rob Griffiths
Twitter: @bytespider
Github: https://github.com/bytespider

bytespider.eu
Sent with Sparrow <http://www.sparrowmailapp.com/?sig>

On Friday, 28 October 2011 at 16:25, Dmitry Pashkevich wrote:

The benefit is visible but when looking at it I have fear that by using the
Promises methodology (and in our case it's just a syntactic sugar for js)
you can easily get tricked by thinking that actually asynchronous stuff is
happening synchronously and eventually fall in your own traps.
But I get the point, it's an interesting approach, thanks for sharing!

-- 
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]


  --
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]

 --
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]

-- 
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