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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Felipe Bernardes
May 16, 2016
Programming
1
91
Javascript Promises
Lightning talk about Promises @ SorocabaJs
Felipe Bernardes
May 16, 2016
Tweet
Share
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
96
An Animated Poem, built with CSS drawings & animations
felipebernardes
1
210
Todas as falhas da minha carreira (até outubro/2019)
felipebernardes
0
83
Immersive Journalism using AR/VR
felipebernardes
0
230
7 Formas de Melhorar seu Networking
felipebernardes
0
48
BEM Show & Tell @ Space Coworking
felipebernardes
0
48
Get Started With PWAs
felipebernardes
0
200
CSS Layouting::putting things into place
felipebernardes
0
64
Other Decks in Programming
See All in Programming
Fragmented Architectures
denyspoltorak
0
140
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
970
re:Invent 2025 トレンドからみる製品開発への AI Agent 活用
yoskoh
0
720
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
630
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
220
AtCoder Conference 2025
shindannin
0
1k
AgentCoreとHuman in the Loop
har1101
5
210
Pythonではじめるオープンデータ分析〜書籍の紹介と書籍で紹介しきれなかった事例の紹介〜
welliving
3
870
公共交通オープンデータ × モバイルUX 複雑な運行情報を 『直感』に変換する技術
tinykitten
PRO
0
200
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
170
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
110
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
440
Featured
See All Featured
Making Projects Easy
brettharned
120
6.6k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.8k
The agentic SEO stack - context over prompts
schlessera
0
610
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
720
Statistics for Hackers
jakevdp
799
230k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
200
Amusing Abliteration
ianozsvald
0
92
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
130
The Language of Interfaces
destraynor
162
26k
AI: The stuff that nobody shows you
jnunemaker
PRO
2
230
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.5k
Building Applications with DynamoDB
mza
96
6.9k
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!