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
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
990
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
970
Other Decks in Programming
See All in Programming
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.8k
OSINT for SRE: 学術論文とポストモーテムから探る システム障害の共通パターン / SRE NEXT 2026
tomoyk
1
1.1k
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
830
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
490
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.3k
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
470
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
140
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
190
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.9k
「正の参照」と 「負の導出」で組む ハーネスエンジニアリング
cottpan
1
120
エンジニアにデザインハーネスを 〜デザインプロセスを規定するためのハーネス〜 / Design harness from an engineer's perspective
rkaga
2
750
Featured
See All Featured
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
Color Theory Basics | Prateek | Gurzu
gurzu
0
380
Game over? The fight for quality and originality in the time of robots
wayneb77
1
220
エンジニアに許された特別な時間の終わり
watany
107
250k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.8k
The Curse of the Amulet
leimatthew05
2
13k
WENDY [Excerpt]
tessaabrams
11
38k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
750
Practical Orchestrator
shlominoach
191
11k
Statistics for Hackers
jakevdp
799
230k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
180
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