Skip to main content

Bug Tracker

Side navigation

#9398 closed enhancement (fixed)

Opened May 22, 2011 07:20PM UTC

Closed September 22, 2011 02:15PM UTC

Last modified March 09, 2012 12:29AM UTC

Proposal for Improved Deferreds

Reported by: jaubourg Owned by: jaubourg
Priority: blocker Milestone: 1.7
Component: deferred Version: 1.6.1
Keywords: 1.7-discuss Cc:
Blocked by: Blocking:
Description

This proposal is a two parter:

1. introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications,

2. while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily.

All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects.

To have an idea of how it would work, see:

Attachments (0)
Change History (16)

Changed May 22, 2011 07:27PM UTC by john comment:1

keywords: → 1.7-discuss

Nominating ticket for 1.7 discussion.

Changed May 22, 2011 08:29PM UTC by rwaldron comment:2

description: This proposal is a two parter: \ 1) introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications, \ 2) while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily. \ \ All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects. \ \ To have an idea of how it would work, see: \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/callbacks.js#L17 for the Callbacks constructor \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/deferred.js#L10 for how the base object can be used to create your own objects (here a Deferred)This proposal is a two parter:\ 1) introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications,\ 2) while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily.\ \ All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects.\ \ To have an idea of how it would work, see:\ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/callbacks.js#L17 for the Callbacks constructor\ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/deferred.js#L10 for how the base object can be used to create your own objects (here a Deferred)

+1, DRY opportunity

Changed May 23, 2011 01:07AM UTC by jaubourg comment:3

+1,

Changed May 23, 2011 05:11AM UTC by timmywil comment:4

+1,

Changed May 24, 2011 12:22AM UTC by jaubourg comment:5

description: This proposal is a two parter:\ 1) introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications,\ 2) while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily.\ \ All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects.\ \ To have an idea of how it would work, see:\ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/callbacks.js#L17 for the Callbacks constructor\ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/deferred.js#L10 for how the base object can be used to create your own objects (here a Deferred)This proposal is a two parter: \ 1) introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications, \ 2) while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily. \ \ All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects. \ \ To have an idea of how it would work, see: \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/callbacks.js#L17 for the Callbacks constructor \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/deferred.js#L10 for how the base object can be used to create your own objects (here a Deferred)

I added a crude named channel system to give an idea of how pub/sub could be implemented using $.Callbacks: https://github.com/jquery/jquery/commit/96b0089c9ce5c65f9d002966256d90e778345a2a

Changed May 24, 2011 12:23AM UTC by jaubourg comment:6

description: This proposal is a two parter: \ 1) introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications, \ 2) while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily. \ \ All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects. \ \ To have an idea of how it would work, see: \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/callbacks.js#L17 for the Callbacks constructor \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/deferred.js#L10 for how the base object can be used to create your own objects (here a Deferred)This proposal is a two parter: \ 1. introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications, \ 2. while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily. \ \ All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects. \ \ To have an idea of how it would work, see: \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/callbacks.js#L17 for the Callbacks constructor \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/deferred.js#L10 for how the base object can be used to create your own objects (here a Deferred)

Changed May 24, 2011 12:24AM UTC by timmywil comment:7

component: unfileddeferred
owner: → jaubourg
priority: undecidedhigh
status: newassigned

Changed May 24, 2011 10:31PM UTC by dmethvin comment:8

+1, Let me get this straight. Jaubourg is proposing to reduce code size? Damn I'm gonna vote for this just to see him try!

Changed June 03, 2011 02:12PM UTC by john comment:9

description: This proposal is a two parter: \ 1. introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications, \ 2. while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily. \ \ All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects. \ \ To have an idea of how it would work, see: \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/callbacks.js#L17 for the Callbacks constructor \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/deferred.js#L10 for how the base object can be used to create your own objects (here a Deferred)This proposal is a two parter:\ 1. introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications,\ 2. while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily.\ \ All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects.\ \ To have an idea of how it would work, see:\ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/callbacks.js#L17 for the Callbacks constructor\ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/deferred.js#L10 for how the base object can be used to create your own objects (here a Deferred)

+0

Changed June 04, 2011 10:19PM UTC by addyosmani comment:10

_comment0: +01316784639978055

+1

Changed June 05, 2011 09:55PM UTC by ajpiano comment:11

description: This proposal is a two parter:\ 1. introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications,\ 2. while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily.\ \ All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects.\ \ To have an idea of how it would work, see:\ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/callbacks.js#L17 for the Callbacks constructor\ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/deferred.js#L10 for how the base object can be used to create your own objects (here a Deferred)This proposal is a two parter: \ 1. introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications, \ 2. while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily. \ \ All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects. \ \ To have an idea of how it would work, see: \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/callbacks.js#L17 for the Callbacks constructor \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/deferred.js#L10 for how the base object can be used to create your own objects (here a Deferred)

+1

Changed June 06, 2011 02:54PM UTC by danheberden comment:12

description: This proposal is a two parter: \ 1. introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications, \ 2. while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily. \ \ All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects. \ \ To have an idea of how it would work, see: \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/callbacks.js#L17 for the Callbacks constructor \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/deferred.js#L10 for how the base object can be used to create your own objects (here a Deferred)This proposal is a two parter:\ 1. introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications,\ 2. while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily.\ \ All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects.\ \ To have an idea of how it would work, see:\ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/callbacks.js#L17 for the Callbacks constructor\ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/deferred.js#L10 for how the base object can be used to create your own objects (here a Deferred)

+1

Changed July 12, 2011 02:49PM UTC by dmethvin comment:13

description: This proposal is a two parter:\ 1. introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications,\ 2. while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily.\ \ All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects.\ \ To have an idea of how it would work, see:\ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/callbacks.js#L17 for the Callbacks constructor\ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/deferred.js#L10 for how the base object can be used to create your own objects (here a Deferred)This proposal is a two parter: \ 1. introduce progress callbacks on Deferreds (just as suggested in the Promise/A proposal). It's kind of a first step before being able to support xhr2 upload and is a much needed addition when dealing with asynchronous tasks that take a non-trivial amount of time to complete and would profit from progression notifications, \ 2. while working on adding progress callbacks I realized that, while different, the logic for the progress callbacks list wasn't that far away from the one of the other two callbacks lists (the only real difference being that the progress callbacks can be called several times, while done and fail ones are only fired once). This brought me to scrap $._Deferred and go for a much more generic $.Callbacks. The advantage is that I can now implement done, fail and progress callbacks with the same base object. It also gives us an opportunity to factor our different callbacks lists throughout jQuery (meaning more robustness and a diminished code size). It can also be made public so that users can start creating callbacks lists easily. \ \ All my experiments are located in the 1.7/callbacks branch. Still a work in progress, of course. Progress callbacks are in (though buggy atm because I screwed the memory logic of repeatable Callbacks but I'm working on it), $.when supports progress callbacks already. All instances of $._Deferred have been replaced by $.Callbacks objects. \ \ To have an idea of how it would work, see: \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/callbacks.js#L17 for the Callbacks constructor \ - https://github.com/jquery/jquery/blob/1.7%2Fcallbacks/src/deferred.js#L10 for how the base object can be used to create your own objects (here a Deferred)
milestone: 1.next1.7
priority: highblocker

Changed September 19, 2011 02:56PM UTC by timmywil comment:14

@jaubourg: jörn, dave, and I were wondering if all of the flags were necessary. If they are not going to be used in 1.7, we may want to wait until 1.8 to add them. Could you provide more details on their usefulness?

Changed September 20, 2011 12:59AM UTC by jaubourg comment:15

once and memory are used by $.Deferred.

unique, stopOnFalse and addAfterFire are useful for event-like lists (unique ensures the same handler will only be called once, stopOnFalse ensures you can "interrupt" firing the list, addAfterFire makes it so when you add a new callback to the list while it is firing then said callback won't be fired as part of current run).

relocate I added after a discussion with Yehuda at jqcon when he told me he had a need for "Deferreds that would have some kind of callback re-ordering facility" (a reverse option would be nice to have callbacks called from the last to the first one in the same vein btw).

queue is more of an experimental flag I put hoping, at the time, that we may be able to replace existing queues with $.Callbacks-based queues.

Apart from queue, these flags are pretty generic in what they do. Just tried to cover as much ground as possible. Not sure about the flag names to be honest, as usual, any help with that is more than welcome.

I'm also not sure the complexity added with the filter parameter is really needed. Just let me know what your review brings and I'll gladly cut (this was the sense of my request for a code review).