Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Javascript Promises
Search
Felipe Bernardes
May 16, 2016
Programming
110
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
130
15 JavaScript Do's & Don'ts
felipebernardes
0
120
An Animated Poem, built with CSS drawings & animations
felipebernardes
1
250
Todas as falhas da minha carreira (até outubro/2019)
felipebernardes
0
92
Immersive Journalism using AR/VR
felipebernardes
0
260
7 Formas de Melhorar seu Networking
felipebernardes
0
62
BEM Show & Tell @ Space Coworking
felipebernardes
0
67
Get Started With PWAs
felipebernardes
0
220
CSS Layouting::putting things into place
felipebernardes
0
73
Other Decks in Programming
See All in Programming
contenteditable と日本語入力に向き合う
colorful12
0
190
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
730
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
34
16k
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.8k
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
1
2.3k
wkhtmltopdfの次どうするか問題2026
willnet
2
1.9k
AWSに止められる覚悟してますか?
morizo_1984
2
530
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
1
250
プロダクトコードからライブラリの境界を見つける
elmetal
PRO
0
110
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
R8 の設定見直しでアプリサイズ削減
andpad
0
210
Featured
See All Featured
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
430
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
440
Ethics towards AI in product and experience design
skipperchong
2
420
The agentic SEO stack - context over prompts
schlessera
0
970
Navigating Weather and Climate Data
rabernat
0
550
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
460
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
980
My Coaching Mixtape
mlcsv
0
350
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
560
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Believing is Seeing
oripsolob
1
240
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!