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
85
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
110
15 JavaScript Do's & Don'ts
felipebernardes
0
85
An Animated Poem, built with CSS drawings & animations
felipebernardes
1
150
Todas as falhas da minha carreira (até outubro/2019)
felipebernardes
0
74
Immersive Journalism using AR/VR
felipebernardes
0
160
7 Formas de Melhorar seu Networking
felipebernardes
0
38
BEM Show & Tell @ Space Coworking
felipebernardes
0
43
Get Started With PWAs
felipebernardes
0
150
CSS Layouting::putting things into place
felipebernardes
0
47
Other Decks in Programming
See All in Programming
Recoilを剥がしている話
kirik
5
8.1k
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
170
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
710
情報漏洩させないための設計
kubotak
5
1.2k
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
8
1.8k
技術的負債と向き合うカイゼン活動を1年続けて分かった "持続可能" なプロダクト開発
yuichiro_serita
0
230
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
380
GitHubで育つ コラボレーション文化 : ニフティでのインナーソース挑戦事例 - 2024-12-16 GitHub Universe 2024 Recap in ZOZO
niftycorp
PRO
0
930
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
6
1.3k
ATDDで素早く安定した デリバリを実現しよう!
tonnsama
1
430
命名をリントする
chiroruxx
1
540
iOS開発におけるCopilot For XcodeとCode Completion / copilot for xcode
fuyan777
1
1k
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
34
1.6k
Optimizing for Happiness
mojombo
376
70k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
Writing Fast Ruby
sferik
628
61k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
The Invisible Side of Design
smashingmag
299
50k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
How GitHub (no longer) Works
holman
312
140k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
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!