Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
JavaScript Promises
Search
Lean Machine
September 04, 2013
Programming
1.1k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JavaScript Promises
Lean Machine
September 04, 2013
More Decks by Lean Machine
See All by Lean Machine
Graceful Degradation with Modernizr
leanmachine
1
1k
Intro to HTML5
leanmachine
3
1k
Organizing Stylesheets with CSS Pre-processors
leanmachine
2
970
Responsive Web Design in a Nutshell
leanmachine
3
140
Seven UX Design Rules
leanmachine
9
1k
JavaScript Closures
leanmachine
1
1.1k
JavaScript Inheritance
leanmachine
2
1.1k
Asynchronous JavaScript
leanmachine
1
980
Other Decks in Programming
See All in Programming
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
200
The Rails Doctrine Decade
koic
2
120
Jetpack Compose メカニズム
skydoves
0
440
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
320
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
4
2.7k
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
1
490
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
4
700
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
250
wkhtmltopdfの次どうするか問題2026
willnet
2
1.5k
cdk deploy JawsSonic #MARATHONしながらAWSリソースをデプロイしてみよう
akihisaikeda
2
140
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
260
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
150
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Between Models and Reality
mayunak
4
460
BBQ
matthewcrist
89
10k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
500
Color Theory Basics | Prateek | Gurzu
gurzu
1
470
Done Done
chrislema
186
16k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
540
Statistics for Hackers
jakevdp
799
230k
Become a Pro
speakerdeck
PRO
31
6.3k
Bash Introduction
62gerente
615
220k
Transcript
var api = require('./obfuscated/api'); var async = require('async'); async.parallel([
function(callback) { api('http//api.somesite.com/getCurrentUser', function(err, currentUser) { if (err) { callback(err); } else { api('http//api.somesite.com/user/' + currentUser.id + '/friends', callback); } }); }, function(callback) { api('http//api.somesite.com/listPeople', callback); } ], function(err, res) { var currentUserFriends = res[0]; var listPeople = res[1]; var notFriends = listPeople.length -‐ currentUserFriends.length; console.log("not friended: " + notFriends); });
var util = require('./obfuscated/util'); var currentUser = util.api('http//api.somesite.com/getCurrentUser'); var urlToCurrentUserFriends
= util.concatStrings('http//api.somesite.com/user/', currentUser.get('id'), '/friends'); var currentFriends = util.api(urlToCurrentUserFriends); var allPeople = util.api('http//api.somesite.com/listPeople'); var notFriends = util.subtract(allPeople.get('length'), currentFriends.get('length')); util.print(util.concatStrings('not friended: ', notFriends));
Promises No more callbacks leanmachine.se ▪
[email protected]
▪ 2013-09-06
A promise is an object that represents the return value
or the thrown exception that a function may eventually provide.
var api = require('./obfuscated/api'); var async = require('async'); async.parallel([
function(callback) { api('http//api.somesite.com/getCurrentUser', function(err, currentUser) { if (err) { callback(err); } else { api('http//api.somesite.com/user/' + currentUser.id + '/friends', callback); } }); }, function(callback) { api('http//api.somesite.com/listPeople', callback); } ], function(err, res) { var currentUserFriends = res[0]; var listPeople = res[1]; var notFriends = listPeople.length -‐ currentUserFriends.length; console.log("not friended: " + notFriends); });
var util = require('./obfuscated/util'); var currentUser = util.api('http//api.somesite.com/getCurrentUser'); var urlToCurrentUserFriends
= util.concatStrings('http//api.somesite.com/user/', currentUser.get('id'), '/friends'); var currentFriends = util.api(urlToCurrentUserFriends); var allPeople = util.api('http//api.somesite.com/listPeople'); var notFriends = util.subtract(allPeople.get('length'), currentFriends.get('length')); util.print(util.concatStrings('not friended: ', notFriends));
var util = require('./obfuscated/util'); var currentUser = util.api('http//api.somesite.com/getCurrentUser'); var urlToCurrentUserFriends
= util.concatStrings('http//api.somesite.com/user/', currentUser.get('id'), '/friends'); var currentFriends = util.api(urlToCurrentUserFriends); var allPeople = util.api('http//api.somesite.com/listPeople'); var notFriends = util.subtract(allPeople.get('length'), currentFriends.get('length')); util.print(util.concatStrings('not friended: ', notFriends)); currentUserFriends.then(function(value) { console.log("current user friends:") console.log(value); });
Coding time!
leanmachine.se ▪
[email protected]
▪ 2013-09-06