On Thursday, February 23, 2012 2:02:12 PM UTC-5, Kris Kowal wrote:
> This guy
> https://twitter.com/#!/trevorburnham
> Wrote a blog on promises in jQuery
> http://net.tutsplus.com/tutorials/javascript-ajax/wrangle-async-tasks...
> And has a Kickstarter project to fund a book on async programming
> http://www.kickstarter.com/projects/869786663/async-javascript-book
> It seems that my early mistake of confusing "resolved" and "fulfilled"
> has become widespread. It is enshrined in the jQuery promise
> implementation now. Thankfully, jQuery’s isResolved is deprecated.
> http://api.jquery.com/deferred.state/
> http://api.jquery.com/category/deferred-object/
> For the record:
> A deferred has two states:
> - "pending"
> - "resolved"
> The resolution is (or becomes) another promise internally! All of the
> "then" calls (and all other messages) that were called on this
> deferred promise get forwarded to the next promise.
> There are three kinds of promises:
> - "fulfilled"
> - "rejected"
> - "deferred"
> If you call deferred.resolve with a non-promise value, it gets
> converted to a fulfilled promise internally. In that case, "resolve"
> means "fulfill".
> Here’s an over-simplified implementation of each type of promise:
> function fulfilled(value) {
> return {
> then: function (callback, errback) {
> var next = Q.defer();
> next.resolve(callback(value));
> return next.promise;
> }
> }
> }
> function rejected(error) {
> return {
> then: function (callback, errback) {
> var next = Q.defer();
> next.resolve(errback(error));
> return next.promise;
> }
> }
> }
> function defer() {
> var pending = [];
> var next;
> return {
> promise: {
> then: function (callback, errback) {
> if (pending) {
> pending.push([callback, errback]);
> } else {
> next.then(callback, errback);
> }
> }
> },
> resolve: function (value) {
> if (value != null && value.then != null) {
> next = value;
> } else {
> next = fulfilled(value);
> }
> pending.forEach(function (args) {
> nextTick(function () {
> next.then.apply(next, args);
> });
> })
> pending = null;
> }
> }
> }
> Kris Kowal
On Thursday, February 23, 2012 2:02:12 PM UTC-5, Kris Kowal wrote:
> This guy
> https://twitter.com/#!/trevorburnham
> Wrote a blog on promises in jQuery
> http://net.tutsplus.com/tutorials/javascript-ajax/wrangle-async-tasks...
> And has a Kickstarter project to fund a book on async programming
> http://www.kickstarter.com/projects/869786663/async-javascript-book
> It seems that my early mistake of confusing "resolved" and "fulfilled"
> has become widespread. It is enshrined in the jQuery promise
> implementation now. Thankfully, jQuery’s isResolved is deprecated.
> http://api.jquery.com/deferred.state/
> http://api.jquery.com/category/deferred-object/
> For the record:
> A deferred has two states:
> - "pending"
> - "resolved"
> The resolution is (or becomes) another promise internally! All of the
> "then" calls (and all other messages) that were called on this
> deferred promise get forwarded to the next promise.
> There are three kinds of promises:
> - "fulfilled"
> - "rejected"
> - "deferred"
> If you call deferred.resolve with a non-promise value, it gets
> converted to a fulfilled promise internally. In that case, "resolve"
> means "fulfill".
> Here’s an over-simplified implementation of each type of promise:
> function fulfilled(value) {
> return {
> then: function (callback, errback) {
> var next = Q.defer();
> next.resolve(callback(value));
> return next.promise;
> }
> }
> }
> function rejected(error) {
> return {
> then: function (callback, errback) {
> var next = Q.defer();
> next.resolve(errback(error));
> return next.promise;
> }
> }
> }
> function defer() {
> var pending = [];
> var next;
> return {
> promise: {
> then: function (callback, errback) {
> if (pending) {
> pending.push([callback, errback]);
> } else {
> next.then(callback, errback);
> }
> }
> },
> resolve: function (value) {
> if (value != null && value.then != null) {
> next = value;
> } else {
> next = fulfilled(value);
> }
> pending.forEach(function (args) {
> nextTick(function () {
> next.then.apply(next, args);
> });
> })
> pending = null;
> }
> }
> }
> Kris Kowal
On Thursday, February 23, 2012 2:02:12 PM UTC-5, Kris Kowal wrote:
> This guy
> https://twitter.com/#!/trevorburnham
> Wrote a blog on promises in jQuery
> http://net.tutsplus.com/tutorials/javascript-ajax/wrangle-async-tasks...
> And has a Kickstarter project to fund a book on async programming
> http://www.kickstarter.com/projects/869786663/async-javascript-book
> It seems that my early mistake of confusing "resolved" and "fulfilled"
> has become widespread. It is enshrined in the jQuery promise
> implementation now. Thankfully, jQuery’s isResolved is deprecated.
> http://api.jquery.com/deferred.state/
> http://api.jquery.com/category/deferred-object/
> For the record:
> A deferred has two states:
> - "pending"
> - "resolved"
> The resolution is (or becomes) another promise internally! All of the
> "then" calls (and all other messages) that were called on this
> deferred promise get forwarded to the next promise.
> There are three kinds of promises:
> - "fulfilled"
> - "rejected"
> - "deferred"
> If you call deferred.resolve with a non-promise value, it gets
> converted to a fulfilled promise internally. In that case, "resolve"
> means "fulfill".
> Here’s an over-simplified implementation of each type of promise:
> function fulfilled(value) {
> return {
> then: function (callback, errback) {
> var next = Q.defer();
> next.resolve(callback(value));
> return next.promise;
> }
> }
> }
> function rejected(error) {
> return {
> then: function (callback, errback) {
> var next = Q.defer();
> next.resolve(errback(error));
> return next.promise;
> }
> }
> }
> function defer() {
> var pending = [];
> var next;
> return {
> promise: {
> then: function (callback, errback) {
> if (pending) {
> pending.push([callback, errback]);
> } else {
> next.then(callback, errback);
> }
> }
> },
> resolve: function (value) {
> if (value != null && value.then != null) {
> next = value;
> } else {
> next = fulfilled(value);
> }
> pending.forEach(function (args) {
> nextTick(function () {
> next.then.apply(next, args);
> });
> })
> pending = null;
> }
> }
> }
> Kris Kowal
On Thursday, February 23, 2012 2:02:12 PM UTC-5, Kris Kowal wrote:
> This guy
> https://twitter.com/#!/trevorburnham
> Wrote a blog on promises in jQuery
> http://net.tutsplus.com/tutorials/javascript-ajax/wrangle-async-tasks...
> And has a Kickstarter project to fund a book on async programming
> http://www.kickstarter.com/projects/869786663/async-javascript-book
> It seems that my early mistake of confusing "resolved" and "fulfilled"
> has become widespread. It is enshrined in the jQuery promise
> implementation now. Thankfully, jQuery’s isResolved is deprecated.
> http://api.jquery.com/deferred.state/
> http://api.jquery.com/category/deferred-object/
> For the record:
> A deferred has two states:
> - "pending"
> - "resolved"
> The resolution is (or becomes) another promise
...