presentation i promised myself - github...recap - promises • promises are an elegant concept of...
TRANSCRIPT
![Page 1: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/1.jpg)
I PROMISED MYSELFChristian Ulbrich, Zalari UG
![Page 2: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/2.jpg)
AGENDA PROPAGANDA• Recap: Promises
• Anti-Patterns
• Common use cases
• Advanced Example - lazyCache
• Links
![Page 3: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/3.jpg)
RECAP - PROMISES
„Promises are the monad of asynchronous programming"
![Page 4: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/4.jpg)
RECAP - PROMISES
![Page 5: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/5.jpg)
RECAP - PROMISES
• Promises are an elegant concept of modeling asynchronous data flows
• Promises are not JS-specific, but can be found in other language as well
• Promises avoid the pyramid of doom aka callback hell
![Page 6: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/6.jpg)
RECAP - PROMISES
![Page 7: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/7.jpg)
RECAP - PROMISES
![Page 8: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/8.jpg)
RECAP - PROMISES• Promises are something, that can either be fulfilled or rejected
• a Promise has two main methods
• then(callback) , that gets called, when the promise is fulfilled
• catch(callback), that gets called, when the promise is rejected
![Page 9: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/9.jpg)
WHY - PROMISES
• Promises are native in ECMAScript 6 and current NodeJS
• a growing number of standard functions return Promises
• the order does not matter, i.e. attach then before or after a promise resolves / rejects
![Page 10: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/10.jpg)
PROMISES - ORDER
![Page 11: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/11.jpg)
PROMISES - ORDER
![Page 12: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/12.jpg)
PROMISES - NATIVE
![Page 13: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/13.jpg)
PROMISES - NATIVE
![Page 14: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/14.jpg)
ANTI-PATTERNS
• nested promises
• superfluous deferred
• then-callback-style
![Page 15: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/15.jpg)
ANTI-PATTERNSNESTED PROMISES
![Page 16: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/16.jpg)
ANTI-PATTERNSNESTED PROMISES
![Page 17: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/17.jpg)
ANTI-PATTERNSSUPERFLUOUS DEFERRED
![Page 18: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/18.jpg)
ANTI-PATTERNSSUPERFLUOUS DEFERRED
![Page 19: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/19.jpg)
ANTI-PATTERNSTHEN-CALLBACK STYLE
![Page 20: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/20.jpg)
ANTI-PATTERNSTHEN-CALLBACK STYLE
![Page 21: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/21.jpg)
COMMON USE CASE
• doing things in parallel
• doing things in sequence
• same interfaces for sync / async code
![Page 22: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/22.jpg)
COMMON USE CASEPARALLELISM
![Page 23: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/23.jpg)
SEQUENCE
![Page 24: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/24.jpg)
COMMON USE CASESAME INTERFACES
![Page 25: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/25.jpg)
ADVANCED EXAMPLE - LAZY CACHE
• we need to fetch data
• fetch is async
• we want to hide details of cache
• interface should always be the same
![Page 26: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/26.jpg)
LAZYCACHE
![Page 27: presentation I promised myself - GitHub...RECAP - PROMISES • Promises are an elegant concept of modeling asynchronous data flows • Promises are not JS-specific, but can be found](https://reader034.vdocuments.mx/reader034/viewer/2022042315/5f03a99a7e708231d40a27f4/html5/thumbnails/27.jpg)
LINKS• Promises are the monad of asynchronous
programming http://bit.ly/1pH8qxJ
• Callbacks are Imperative, Promises are functional: http://bit.ly/1hwxDEf
• Promise Anti-Patterns http://bit.ly/1bKThTD
• Promise Tutorial http://bit.ly/1fgVvY9