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
Javascript Promises
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Felipe Bernardes
May 16, 2016
Programming
91
1
Share
Javascript Promises
Lightning talk about Promises @ SorocabaJs
Felipe Bernardes
May 16, 2016
More Decks by Felipe Bernardes
See All by Felipe Bernardes
Gardening for Communities - Organically Cultivating Local Communities
felipebernardes
0
120
15 JavaScript Do's & Don'ts
felipebernardes
0
100
An Animated Poem, built with CSS drawings & animations
felipebernardes
1
230
Todas as falhas da minha carreira (até outubro/2019)
felipebernardes
0
85
Immersive Journalism using AR/VR
felipebernardes
0
240
7 Formas de Melhorar seu Networking
felipebernardes
0
51
BEM Show & Tell @ Space Coworking
felipebernardes
0
49
Get Started With PWAs
felipebernardes
0
210
CSS Layouting::putting things into place
felipebernardes
0
66
Other Decks in Programming
See All in Programming
Agentic Elixir
whatyouhide
0
410
Road to RubyKaigi: Play Hard(ware)
makicamel
1
470
Vibe NLP for Applied NLP
inesmontani
PRO
0
480
🦞OpenClaw works with AWS
licux
1
240
Claude Codeをカスタムして自分だけのClaude Codeを作ろう
terisuke
0
150
AIを導入する前にやるべきこと
negima
2
250
VueエンジニアがReactを触って感じた_設計の違い
koukimiura
0
180
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
2.6k
煩雑なSkills管理をSoC(関心の分離)により解決する――関心を分離し、プロンプトを部品として育てるためのOSSを作った話 / Solving Complex Skills Management Through SoC (Separation of Concerns)
nrslib
4
1k
Spec Driven Development | AI Summit Vilnius
danielsogl
PRO
1
110
実用!Hono RPC2026
yodaka
2
270
第3木曜LT会 #28
tinykitten
PRO
0
110
Featured
See All Featured
Deep Space Network (abreviated)
tonyrice
0
120
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
160
WCS-LA-2024
lcolladotor
0
550
Practical Orchestrator
shlominoach
191
11k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.4k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
900
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
130
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
270
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Automating Front-end Workflow
addyosmani
1370
200k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.2k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
820
Transcript
promises && js2015 felipe bernardes github.com/felipebernardes
http://felipebernardes.github.io #votorantim http://tegra.me 2
None
execution stack && contexts
None
console.log(‘1’); setTimeout(() => console.log(‘2’), 0); console.log(‘3’); setTimeout(() => console.log(‘4’), 1000);
//1324
why promise?
None
• no more callback hell || pyramid of d00m ◦
better performance • cleaner && less code ◦ better to undestand ◦ easier to maintain ◦ responsabilities && modularization • better error handling
why not promise?
None
how to promise
doThis(param) .then( response => this.someAttr = param);
( ... ) //syncronous code doThis(param) .then( response => this.someAttr
= param); ( ... ) //syncronous code
doThis(param) .then( response => this.someAttr = param) .catch ( errorResponse
=> console.log(errorResponse) );
all && race
all http://jsfiddle.net/jsengel/mc3p01nb/ then after all promises returned, catch if any
of them fails
race then after one of the promises returns, catch if
any of them fails
var p3 = new Promise(function(resolve, reject) { setTimeout(resolve, 100, "three");
}); var p4 = new Promise(function(resolve, reject) { setTimeout(reject, 500, "four"); }); Promise.race([p3, p4]).then(function(value) { console.log(value); //three }
example
const setStatus = (group, status) => { const data =
{ status: status, shopId: group.shop.id, }; return $http.post(`${API}/group/${group.id}/shop/status`, data); }; // service
ShopListService.setStatus(this.group, 'closed') .then( () => this.group.shop.status = 'closed'); // controller
None
further reading
articles
html5rocks http://www.html5rocks.com/en/tutorials/es6/promises nomadev http://nomadev.com.br/angularjs-promises-promessas-o-guia- definitivo/ david walsh https://davidwalsh.name/write-javascript-promises
libs
$q https://github.com/kriskowal/q bluebird http://bluebirdjs.com/
python sorocaba - https://groups.google.com/forum/m/#!forum/python-sorocaba guru sorocaba - https://www.facebook.com/GURUSorocaba/ hacklab -
https://www.facebook.com/hacklabsorocaba/ GDG Sorocaba - https://www.facebook.com/GDGSorocaba/ SorocabaJS - https://www.facebook.com/sorocabajs/ JS Meetup - http://www.meetup.com/GDG-Sorocaba/ WomenTechmakers - https://www.facebook.com/groups/wtmsorocaba/ in.tegra.do - http://www.meetup.com/In-Tegra-Do/ english meetup - http://www.meetup.com/Sorocaba-English-Conversation-Happy-Hours/ #chegaMais
we're hiring
[email protected]
[email protected]
co-authored by felipe l. soares caique mitsuoka jean vitor
speakerdeck.com/felipebernardes valeu!