SlideShare a Scribd company logo
1 of 26
Download to read offline
Promises

           Luke Smith
           SmugMug
           @ls_n
A promise represents a value
that may not be available yet

      var promise = async();




             promise
A promise represents a value
that may not be available yet

      var promise = async();




             promise




   Synchronous code analogy

       var value = sync();
new Y.Promise(workFn)

function async() {


    function getMessage(resolve, reject) {
        setTimeout(function () {


          resolve(“Promise fulfilled”);

        }, 1000);
    }

    return new Y.Promise(getMessage);        promise


}
then() method to get value when available
or catch errors during value computation

         var promise = async();
         promise.then(onFulfilled, onRejected);




         promise       .then(
                         onFulfilled(value)
                           onRejected(reason)
                       )
then() method to get value when available
     or catch errors during value computation

Synchronous code analogy
var value, error;
try {
    value = sync();          promise   .then(
} catch (reason) {                       onFulfilled(value)
    error = reason;
                                           onRejected(reason)
}
                                       )
if (error) {
    onRejected(reason);
} else {
    onFulfilled(value);
}
Promise Resolution



          Fulfillment                           Rejection


promise        .then(                    promise    .then(
 value           onFulfilled( value )      reason      onFulfilled(value)
                   onRejected(reason)                   onRejected( reason )
               )                                    )
 fulfill                                   reject
then() returns a promise

var promiseA = async();

var promiseB = promiseA.then(onFulfilled, onRejected);




           promiseA       .then(
                            onFulfilled(value)
                              onRejected(reason)
                          )

                               promiseB
then() returns a promise


Synchronous code analogy
var valueA, valueB, error;
try {
    valueA = sync();                promiseA   .then(
} catch (reason) {                               onFulfilled(value)
    error = reason;
                                                   onRejected(reason)
}
                                               )
if (error) {
    onRejected(reason);                             promiseB
} else {
    valueB = onFulfilled(valueA);
}
callback return values fulfill their promises




                      return                                   return
.then(                                  .then(
  onFulfilled(value)            value      onRejected(reason)            value
)                                       )

    promise                                 promise
     value                     fulfill        value                      fulfill
callback errors reject their promises




                      throw                                   throw
.then(                                 .then(
  onFulfilled(value)           error      onRejected(reason)           error
)                                      )

    promise                                promise
    reason                    reject       reason                     reject
Promise Chaining
   var promiseC = async()

                     .then(onFulfilledA, onRejectedA)

                     .then(onFulfilledB, onRejectedB);



promiseA      .then(
                onFulfilledA(value)
                  onRejectedA(reason)
              )

                  promiseB           .then(
                                       onFulfilledB(value)
                                         onRejectedB(reason)
                                     )

                                         promiseC           and so on...
callback resolution through the chain



promise1       .then(                   return
value A          onFulfilled(value) A
                            value                 value B
                   onRejected(reason)
               )
 fulfill                                            fulfill
                   promise2
                    value B
                                            .then(                   return
                                              onFulfilled(value) B
                                                         value                value C
                                                onRejected(reason)
                                            )
                                                                               fulfill
                                                 promise3
                                                 value C
Synchronous code analogy
var valueA, valueB, valueC,
    error = false;

try {
    valueA = sync();
} catch (reasonA) {
    error = true;
    valueA = reasonA;
}

if (error) {
    try {
         valueB = onRejectedA(valueA);
         error = false;
    } catch (reasonB) {
         valueB = reasonB;
    }
} else {
    try {
         valueB = onFulfilledA(valueA);
    } catch (reasonB) {
         error = true;
         valueB = reasonB;
    }
}
Synchronous code analogy
var valueA, valueB, valueC,
    error = false;

try {
    valueA = sync();
} catch (reasonA) {
    error = true;
                                              initial promise generation
    valueA = reasonA;
}

if (error) {
    try {
         valueB = onRejectedA(valueA);
         error = false;
    } catch (reasonB) {
         valueB = reasonB;
    }
} else {
    try {
         valueB = onFulfilledA(valueA);
    } catch (reasonB) {
         error = true;
         valueB = reasonB;
    }
}
} catch (reasonA) {
    error = true;
    valueA = reasonA;
}
                                          Synchronous code analogy
if (error) {
    try {
         valueB = onRejectedA(valueA);
         error = false;
    } catch (reasonB) {
         valueB = reasonB;
    }
} else {                                      for each intermediate promise...
    try {
         valueB = onFulfilledA(valueA);
    } catch (reasonB) {
         error = true;
         valueB = reasonB;
    }
}

if (error) {
    valueC = onRejectedB(valueB);
} else {                                      final promise callbacks
    valueC = onFulfilledB(valueB);
}
value/reason pass thru if callback missing



promise1    .then(
                                         return value B
value A       onFulfilled(value) A
                         value
                onRejected(reason)
            )
 fulfill
                promise2             .then(
                                                          pass thru
                 value B               null
                                         onRejected(reason)
                                     )

                                          promise3            .then(
                                           value B              onFulfilled(value) B
                                                                            value
                                                                  onRejected(reason)
                                                              )
callbacks can return promises

    .then(                 return   returned
      onFulfilled(value)
                                    promise
    )

        promise




    .then(                 return   returned
      onRejected(reason)
                                    promise
    )

        promise
callbacks can return promises

    .then(                 return   returned
      onFulfilled(value)                        Not a value (yet)
                                    promise
    )

        promise




    .then(                 return   returned
      onRejected(reason)                       Not a value (yet)
                                    promise
    )

        promise
returned promises postpone continuation

.then(                    return
  onFulfilled(value)                  returned
                                     promise
)

    promise




               .then(
                 onFulfilled(value)
                   onRejected(reason)
               )
returned promises postpone continuation

.then(                                          inserted
  onFulfilled(value)                  returned              .then(
                                     promise                 onFulfilled(value)
)
                                                               onRejected(reason)
    promise                                                )


                                                           “wait for me”



               .then(
                 onFulfilled(value)
                   onRejected(reason)
               )
returned promises postpone continuation

.then(                                          inserted
  onFulfilled(value)                  returned              .then(
                                     promise                 onFulfilled(value)
)
                                      value                    onRejected(reason)
    promise                                                )

                                      fulfill
                                                           “wait for me”



               .then(
                 onFulfilled(value)
                   onRejected(reason)
               )
returned promises postpone continuation

.then(
  onFulfilled(value)                  returned   .then(
                                     promise      onFulfilled( value )
)
                                      value         onRejected(reason)
    promise                                     )

                                      fulfill




               .then(
                 onFulfilled(value)
                   onRejected(reason)
               )
returned promises postpone continuation

.then(
  onFulfilled(value)                  returned                     .then(
                                     promise                        onFulfilled( value )
)
                                      value                           onRejected(reason)
    promise                                                       )
     value                            fulfill
                                                                                                    .
                                                                                            omise..
                                                                                  i   nal pr
                                                                          e s orig
                                                                  e resolv
                                                        en t valu
               .then(                           f ulfillm
                 onFulfilled(value)
                   onRejected(reason)
               )
returned promises postpone continuation

            .then(
              onFulfilled(value)               returned                     .then(
                                              promise                        onFulfilled( value )
            )
                                                value                          onRejected(reason)
                promise                                                    )
                 value                          fulfill
                                                                                                             .
                                                                                                     omise..
                                                                                           i   nal pr
                                                                                   e s orig
                                                                           e resolv
...then chain continues                                          en t valu
                           .then(                        f ulfillm
                             onFulfilled( value )
                               onRejected(reason)
                           )
Promises/A+ spec
http://promises-aplus.github.com/promises-spec/


   https://github.com/promises-aplus/promises-spec

More Related Content

More from Luke Smith

Debugging tips in YUI 3
Debugging tips in YUI 3Debugging tips in YUI 3
Debugging tips in YUI 3Luke Smith
 
YUI 3: Events Evolved
YUI 3: Events EvolvedYUI 3: Events Evolved
YUI 3: Events EvolvedLuke Smith
 
YUI 3 quick overview
YUI 3 quick overviewYUI 3 quick overview
YUI 3 quick overviewLuke Smith
 
YUI 3: Below the Surface
YUI 3: Below the SurfaceYUI 3: Below the Surface
YUI 3: Below the SurfaceLuke Smith
 
Front end engineering, YUI Gallery, and your future
Front end engineering, YUI Gallery, and your futureFront end engineering, YUI Gallery, and your future
Front end engineering, YUI Gallery, and your futureLuke Smith
 

More from Luke Smith (8)

Attribute
AttributeAttribute
Attribute
 
Hack with YUI
Hack with YUIHack with YUI
Hack with YUI
 
Debugging tips in YUI 3
Debugging tips in YUI 3Debugging tips in YUI 3
Debugging tips in YUI 3
 
YUI 3: Events Evolved
YUI 3: Events EvolvedYUI 3: Events Evolved
YUI 3: Events Evolved
 
YUI 3 quick overview
YUI 3 quick overviewYUI 3 quick overview
YUI 3 quick overview
 
YUI 3: Below the Surface
YUI 3: Below the SurfaceYUI 3: Below the Surface
YUI 3: Below the Surface
 
Yui3
Yui3Yui3
Yui3
 
Front end engineering, YUI Gallery, and your future
Front end engineering, YUI Gallery, and your futureFront end engineering, YUI Gallery, and your future
Front end engineering, YUI Gallery, and your future
 

Recently uploaded

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 

Promises. The basics, from Promises/A+

  • 1. Promises Luke Smith SmugMug @ls_n
  • 2. A promise represents a value that may not be available yet var promise = async(); promise
  • 3. A promise represents a value that may not be available yet var promise = async(); promise Synchronous code analogy var value = sync();
  • 4. new Y.Promise(workFn) function async() { function getMessage(resolve, reject) { setTimeout(function () { resolve(“Promise fulfilled”); }, 1000); } return new Y.Promise(getMessage); promise }
  • 5. then() method to get value when available or catch errors during value computation var promise = async(); promise.then(onFulfilled, onRejected); promise .then( onFulfilled(value) onRejected(reason) )
  • 6. then() method to get value when available or catch errors during value computation Synchronous code analogy var value, error; try { value = sync(); promise .then( } catch (reason) { onFulfilled(value) error = reason; onRejected(reason) } ) if (error) { onRejected(reason); } else { onFulfilled(value); }
  • 7. Promise Resolution Fulfillment Rejection promise .then( promise .then( value onFulfilled( value ) reason onFulfilled(value) onRejected(reason) onRejected( reason ) ) ) fulfill reject
  • 8. then() returns a promise var promiseA = async(); var promiseB = promiseA.then(onFulfilled, onRejected); promiseA .then( onFulfilled(value) onRejected(reason) ) promiseB
  • 9. then() returns a promise Synchronous code analogy var valueA, valueB, error; try { valueA = sync(); promiseA .then( } catch (reason) { onFulfilled(value) error = reason; onRejected(reason) } ) if (error) { onRejected(reason); promiseB } else { valueB = onFulfilled(valueA); }
  • 10. callback return values fulfill their promises return return .then( .then( onFulfilled(value) value onRejected(reason) value ) ) promise promise value fulfill value fulfill
  • 11. callback errors reject their promises throw throw .then( .then( onFulfilled(value) error onRejected(reason) error ) ) promise promise reason reject reason reject
  • 12. Promise Chaining var promiseC = async() .then(onFulfilledA, onRejectedA) .then(onFulfilledB, onRejectedB); promiseA .then( onFulfilledA(value) onRejectedA(reason) ) promiseB .then( onFulfilledB(value) onRejectedB(reason) ) promiseC and so on...
  • 13. callback resolution through the chain promise1 .then( return value A onFulfilled(value) A value value B onRejected(reason) ) fulfill fulfill promise2 value B .then( return onFulfilled(value) B value value C onRejected(reason) ) fulfill promise3 value C
  • 14. Synchronous code analogy var valueA, valueB, valueC, error = false; try { valueA = sync(); } catch (reasonA) { error = true; valueA = reasonA; } if (error) { try { valueB = onRejectedA(valueA); error = false; } catch (reasonB) { valueB = reasonB; } } else { try { valueB = onFulfilledA(valueA); } catch (reasonB) { error = true; valueB = reasonB; } }
  • 15. Synchronous code analogy var valueA, valueB, valueC, error = false; try { valueA = sync(); } catch (reasonA) { error = true; initial promise generation valueA = reasonA; } if (error) { try { valueB = onRejectedA(valueA); error = false; } catch (reasonB) { valueB = reasonB; } } else { try { valueB = onFulfilledA(valueA); } catch (reasonB) { error = true; valueB = reasonB; } }
  • 16. } catch (reasonA) { error = true; valueA = reasonA; } Synchronous code analogy if (error) { try { valueB = onRejectedA(valueA); error = false; } catch (reasonB) { valueB = reasonB; } } else { for each intermediate promise... try { valueB = onFulfilledA(valueA); } catch (reasonB) { error = true; valueB = reasonB; } } if (error) { valueC = onRejectedB(valueB); } else { final promise callbacks valueC = onFulfilledB(valueB); }
  • 17. value/reason pass thru if callback missing promise1 .then( return value B value A onFulfilled(value) A value onRejected(reason) ) fulfill promise2 .then( pass thru value B null onRejected(reason) ) promise3 .then( value B onFulfilled(value) B value onRejected(reason) )
  • 18. callbacks can return promises .then( return returned onFulfilled(value) promise ) promise .then( return returned onRejected(reason) promise ) promise
  • 19. callbacks can return promises .then( return returned onFulfilled(value) Not a value (yet) promise ) promise .then( return returned onRejected(reason) Not a value (yet) promise ) promise
  • 20. returned promises postpone continuation .then( return onFulfilled(value) returned promise ) promise .then( onFulfilled(value) onRejected(reason) )
  • 21. returned promises postpone continuation .then( inserted onFulfilled(value) returned .then( promise onFulfilled(value) ) onRejected(reason) promise ) “wait for me” .then( onFulfilled(value) onRejected(reason) )
  • 22. returned promises postpone continuation .then( inserted onFulfilled(value) returned .then( promise onFulfilled(value) ) value onRejected(reason) promise ) fulfill “wait for me” .then( onFulfilled(value) onRejected(reason) )
  • 23. returned promises postpone continuation .then( onFulfilled(value) returned .then( promise onFulfilled( value ) ) value onRejected(reason) promise ) fulfill .then( onFulfilled(value) onRejected(reason) )
  • 24. returned promises postpone continuation .then( onFulfilled(value) returned .then( promise onFulfilled( value ) ) value onRejected(reason) promise ) value fulfill . omise.. i nal pr e s orig e resolv en t valu .then( f ulfillm onFulfilled(value) onRejected(reason) )
  • 25. returned promises postpone continuation .then( onFulfilled(value) returned .then( promise onFulfilled( value ) ) value onRejected(reason) promise ) value fulfill . omise.. i nal pr e s orig e resolv ...then chain continues en t valu .then( f ulfillm onFulfilled( value ) onRejected(reason) )
  • 26. Promises/A+ spec http://promises-aplus.github.com/promises-spec/ https://github.com/promises-aplus/promises-spec