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
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
99
An Animated Poem, built with CSS drawings & animations
felipebernardes
1
220
Todas as falhas da minha carreira (até outubro/2019)
felipebernardes
0
84
Immersive Journalism using AR/VR
felipebernardes
0
230
7 Formas de Melhorar seu Networking
felipebernardes
0
50
BEM Show & Tell @ Space Coworking
felipebernardes
0
49
Get Started With PWAs
felipebernardes
0
200
CSS Layouting::putting things into place
felipebernardes
0
65
Other Decks in Programming
See All in Programming
存在論的プログラミング: 時間と存在を記述する
koriym
3
340
CSC307 Lecture 15
javiergs
PRO
0
260
AWS×クラウドネイティブソフトウェア設計 / AWS x Cloud-Native Software Design
nrslib
16
3.3k
20260315 AWSなんもわからん🥲
chiilog
2
170
Rethinking API Platform Filters
vinceamstoutz
0
140
SourceGeneratorのマーカー属性問題について
htkym
0
210
Goの型安全性で実現する複数プロダクトの権限管理
ishikawa_pro
2
900
Cyrius ーLinux非依存にコンテナをネイティブ実行する専用OSー
n4mlz
0
230
20260228_JAWS_Beginner_Kansai
takuyay0ne
5
610
Agentic AI: Evolution oder Revolution
mobilelarson
PRO
0
190
OTP を自動で入力する裏技
megabitsenmzq
0
120
Symfony + NelmioApiDocBundle を使った スキーマ駆動開発 / Schema Driven Development with NelmioApiDocBundle
okashoi
0
210
Featured
See All Featured
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
130
The agentic SEO stack - context over prompts
schlessera
0
710
Utilizing Notion as your number one productivity tool
mfonobong
4
270
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1k
It's Worth the Effort
3n
188
29k
A Modern Web Designer's Workflow
chriscoyier
698
190k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.5k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Become a Pro
speakerdeck
PRO
31
5.9k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
280
YesSQL, Process and Tooling at Scale
rocio
174
15k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
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!