Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
You don't know Promises - IT Konekt April 2019
Search
Ivan Jovanovic
April 20, 2019
Technology
1
60
You don't know Promises - IT Konekt April 2019
Ivan Jovanovic
April 20, 2019
Tweet
Share
More Decks by Ivan Jovanovic
See All by Ivan Jovanovic
Micro Frontends - A microservice approach to the modern web - Oredev 2019
ivanjov
0
85
Micro Frontends - A microservice approach to the modern web - O'Reilly Software Architecture Berlin 2019
ivanjov
0
68
React State - The Good, the Bad and the Ugly - ArmadaJS
ivanjov
0
120
Thinking Reactive in JavaScript - Sphere.it JS Krakow
ivanjov
0
68
Micro Frontends - A microservice approach to the modern web - PHPSrbija
ivanjov
0
210
Micro Frontends - A microservice approach to the modern web - Codemotion Rome 2019
ivanjov
0
330
Mikro Frontendi - Uvod - Novi Sad JS
ivanjov
0
160
Software engineer marketing done right – career tips from my experience.
ivanjov
0
38
Micro Frontends - A microservice approach to the modern web - Full Stack London 2018
ivanjov
0
230
Other Decks in Technology
See All in Technology
コスト削減から「セキュリティと利便性」を担うプラットフォームへ
sansantech
PRO
1
550
M&A 後の統合をどう進めるか ─ ナレッジワーク × Poetics が実践した組織とシステムの融合
kworkdev
PRO
1
180
Databricks Free Edition講座 データサイエンス編
taka_aki
0
260
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
41k
分析画面のクリック操作をそのままコード化 ! エンジニアとビジネスユーザーが共存するAI-ReadyなBI基盤
ikumi
0
120
SMTP完全に理解した ✉️
yamatai1212
0
150
AI開発の落とし穴 〜馬には乗ってみよAIには添うてみよ〜
sansantech
PRO
10
5.7k
Regional_NAT_Gatewayについて_basicとの違い_試した内容スケールアウト_インについて_IPv6_dual_networkでの使い分けなど.pdf
cloudevcode
1
200
生成AI時代にこそ求められるSRE / SRE for Gen AI era
ymotongpoo
4
1.4k
ZOZOにおけるAI活用の現在 ~開発組織全体での取り組みと試行錯誤~
zozotech
PRO
3
2.1k
EventBridge API Destination × AgentCore Runtimeで実現するLambdaレスなイベント駆動エージェント
har1101
7
290
エンジニアとマネジメントの距離/Engineering and Management
ikuodanaka
3
690
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
1
1.3k
The untapped power of vector embeddings
frankvandijk
1
1.6k
My Coaching Mixtape
mlcsv
0
44
Discover your Explorer Soul
emna__ayadi
2
1.1k
A designer walks into a library…
pauljervisheath
210
24k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
0
190
Music & Morning Musume
bryan
47
7.1k
Exploring anti-patterns in Rails
aemeredith
2
230
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.3k
RailsConf 2023
tenderlove
30
1.3k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.8k
Transcript
You don't know Promises
I am Ivan Jovanovic Senior Software Engineer, Tech Speaker You
can find me at @ivanjov96 or https://ivanjov.com Hello! IJ Consulting
Why I don't know Promises?
None
None
I am here today To show you how Promises really
work!
JavaScript is strange because ‒ It was built for 10
days ‒ It has one thread ‒ It is synchronous and asynchronous ‒ It is everywhere ‒ It is different
Only one thread And the event loop
None
How do we handle async code? Promises Callbacks Async/await
Callbacks Where everything began... 1
“ A callback is a function that is passed as
an argument and will be executed after another function has finished executing.
None
None
Promises Changed everything 2
“ The Promise object represents the eventual completion (or failure)
of an asynchronous operation, and its resulting value.
None
None
How Promises really work? The answer is a Microtask queue!
None
Microtask queue ‒ Independent queue ‒ Used by: process.nextTick, Promises,
Object.observe, MutationObserver ‒ Faster than the main queue and may be drained several times in a single event loop tick
None
Next TICK ONE Next TICK TWO TIMEOUT AFTER-ONE TIMEOUT AFTER-TWO
Promise methods ‒ Promise.all(iterable) ‒ Promise.race(iterable) ‒ Promise.resolve(value) ‒ Promise.reject(reason)
Promise.all(iterable)
Rejected situation
Promise.race(iterable)
Promisify non-Promise code
Native Promises from libraries
Async/await Comes to the rescue 3
“ Async/Await is a special syntax for working with Promises.
None
Most common problems with Promises that we see every day!
9
Nested promises 1
None
None
Broken Promise chain 2
None
None
Mixing sync and async code 3
None
None
None
Missing catch 4
None
None
None
Forget to return a Promise 5
None
None
Promisified synchronous code 6
None
Mixing Promise and Async/Await 7
None
None
Async function that returns Promise 8
None
None
None
Define a callback as an async function 9
None
Clinic.js https://clinicjs.org/
Conclusion ‒ JS is crazy and great at the same
time! ‒ Async behavior is a pro, not a con. ‒ Be careful when using Promises, it's great and dangerous at the same time!
Any questions ? You can find me at ‒ @ivanjov96
‒
[email protected]
Thanks!