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
100
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
110
An Animated Poem, built with CSS drawings & animations
felipebernardes
1
240
Todas as falhas da minha carreira (até outubro/2019)
felipebernardes
0
86
Immersive Journalism using AR/VR
felipebernardes
0
250
7 Formas de Melhorar seu Networking
felipebernardes
0
58
BEM Show & Tell @ Space Coworking
felipebernardes
0
52
Get Started With PWAs
felipebernardes
0
220
CSS Layouting::putting things into place
felipebernardes
0
68
Other Decks in Programming
See All in Programming
Built Our Own Background Agent at LayerX
layerx
PRO
10
5.4k
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
360
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
550
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
1
230
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
590
Android CLI
fornewid
0
220
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
490
GDG Korea Android: 2026 I/O Extended ~ What's new in Android development tools
pluu
0
220
Building a Meta Ray-Ban display app
akkeylab
0
150
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
500
Foundation Models frameworkで画像分析
ryodeveloper
1
610
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
230
Featured
See All Featured
Balancing Empowerment & Direction
lara
6
1.2k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
460
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.2k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
470
Optimising Largest Contentful Paint
csswizardry
37
3.9k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
460
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
119
120k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
300
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!