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
90
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
200
Todas as falhas da minha carreira (até outubro/2019)
felipebernardes
0
83
Immersive Journalism using AR/VR
felipebernardes
0
210
7 Formas de Melhorar seu Networking
felipebernardes
0
48
BEM Show & Tell @ Space Coworking
felipebernardes
0
48
Get Started With PWAs
felipebernardes
0
190
CSS Layouting::putting things into place
felipebernardes
0
64
Other Decks in Programming
See All in Programming
Le côté obscur des IA génératives
pascallemerrer
0
150
iOSでSVG画像を扱う
kishikawakatsumi
0
140
Goで実践するドメイン駆動開発 AIと歩み始めた新規プロダクト開発の現在地
imkaoru
4
870
CSC509 Lecture 08
javiergs
PRO
0
230
理論と実務のギャップを超える
eycjur
0
170
O Que É e Como Funciona o PHP-FPM?
marcelgsantos
0
110
技術的負債の正体を知って向き合う
irof
0
210
コードとあなたと私の距離 / The Distance Between Code, You, and I
hiro_y
0
190
Software Architecture
hschwentner
6
2.3k
スマホから Youtube Shortsを見られないようにする
lemolatoon
27
33k
『毎日の移動』を支えるGoバックエンド内製開発
yutautsugi
2
270
kiroとCodexで最高のSpec駆動開発を!!数時間で web3ネイティブなミニゲームを作ってみたよ!
mashharuki
0
800
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
990
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
920
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
54k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3k
Six Lessons from altMBA
skipperchong
29
4k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.1k
Automating Front-end Workflow
addyosmani
1371
200k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Building a Scalable Design System with Sketch
lauravandoore
463
33k
Why Our Code Smells
bkeepers
PRO
340
57k
Optimizing for Happiness
mojombo
379
70k
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!