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
99
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
55
BEM Show & Tell @ Space Coworking
felipebernardes
0
52
Get Started With PWAs
felipebernardes
0
210
CSS Layouting::putting things into place
felipebernardes
0
68
Other Decks in Programming
See All in Programming
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.3k
コーディングルールの鮮度を保ちたい for SRE NEXT 2026 / keep-fresh-go-internal-conventions-sre-next-2026
handlename
0
150
AIエージェントで 変わるAndroid開発環境
takahirom
2
710
Claude Team Plan導入・ガイド
tk3fftk
0
220
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
4
1.2k
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
520
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
3k
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
160
エンジニアにデザインハーネスを 〜デザインプロセスを規定するためのハーネス〜 / Design harness from an engineer's perspective
rkaga
2
1.7k
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
120
ITヒヤリハットを整理してみた ~ライフサイクルと原因から考える再発防止策~
koukimiura
1
110
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
1
220
Featured
See All Featured
Building Applications with DynamoDB
mza
96
7.1k
Marketing to machines
jonoalderson
1
5.6k
The untapped power of vector embeddings
frankvandijk
2
1.8k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.2k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
It's Worth the Effort
3n
188
29k
Making the Leap to Tech Lead
cromwellryan
135
10k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
320
From π to Pie charts
rasagy
0
240
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
260
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
180
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!