SlideShare a Scribd company logo
Submit Search
Upload
Login
Signup
Promise pattern
Report
Sebastiaan Deckers
Follow
Javascript Jockey at Cofounders.sg
Jul. 8, 2012
•
0 likes
•
8,410 views
1
of
16
Promise pattern
Jul. 8, 2012
•
0 likes
•
8,410 views
Download Now
Download to read offline
Report
Technology
Design
Sebastiaan Deckers
Follow
Javascript Jockey at Cofounders.sg
Recommended
Promises, Promises
Domenic Denicola
22.8K views
•
49 slides
JavaScript Promises
L&T Technology Services Limited
4.5K views
•
32 slides
JavaScript Promise
Joseph Chiang
4.3K views
•
28 slides
JavaScript Promises
Tomasz Bak
1.1K views
•
22 slides
$q and Promises in AngularJS
a_sharif
6.1K views
•
28 slides
Avoiding callback hell in Node js using promises
Ankit Agarwal
5.8K views
•
22 slides
More Related Content
What's hot
Javascript Promises/Q Library
async_io
28.8K views
•
28 slides
The Promised Land (in Angular)
Domenic Denicola
23.1K views
•
42 slides
Getting Comfortable with JS Promises
Asa Kusuma
2.9K views
•
38 slides
JavaScript promise
eslam_me
527 views
•
40 slides
Asynchronous programming done right - Node.js
Piotr Pelczar
6.9K views
•
70 slides
Understanding Asynchronous JavaScript
jnewmanux
3.5K views
•
48 slides
What's hot
(20)
Javascript Promises/Q Library
async_io
•
28.8K views
The Promised Land (in Angular)
Domenic Denicola
•
23.1K views
Getting Comfortable with JS Promises
Asa Kusuma
•
2.9K views
JavaScript promise
eslam_me
•
527 views
Asynchronous programming done right - Node.js
Piotr Pelczar
•
6.9K views
Understanding Asynchronous JavaScript
jnewmanux
•
3.5K views
Java Script Promise
Alok Guha
•
1.1K views
JavaScript Promises
Derek Willian Stavis
•
1K views
Avoiding Callback Hell with Async.js
cacois
•
21.4K views
Avoiding callback hell with promises
TorontoNodeJS
•
996 views
Boom! Promises/A+ Was Born
Domenic Denicola
•
27.5K views
Callbacks and control flow in Node js
Thomas Roch
•
2K views
Async Frontiers
Domenic Denicola
•
2K views
Web Crawling with NodeJS
Sylvain Zimmer
•
119.1K views
The evolution of asynchronous javascript
Alessandro Cinelli (cirpo)
•
1.7K views
ES6: The Awesome Parts
Domenic Denicola
•
59.8K views
Domains!
Domenic Denicola
•
8.3K views
History of jQuery
jeresig
•
9.9K views
ES6 is Nigh
Domenic Denicola
•
8K views
Good karma: UX Patterns and Unit Testing in Angular with Karma
ExoLeaders.com
•
2K views
Similar to Promise pattern
Asynchronous development in JavaScript
Amitai Barnea
330 views
•
25 slides
Intro to Asynchronous Javascript
Garrett Welson
501 views
•
62 slides
Async js - Nemetschek Presentaion @ HackBulgaria
HackBulgaria
886 views
•
20 slides
The evolution of java script asynchronous calls
Huy Hoàng Phạm
34.1K views
•
22 slides
Async JavaScript Unit Testing
Mihail Gaberov
161 views
•
11 slides
Node.js
Mat Schaffer
823 views
•
39 slides
Similar to Promise pattern
(20)
Asynchronous development in JavaScript
Amitai Barnea
•
330 views
Intro to Asynchronous Javascript
Garrett Welson
•
501 views
Async js - Nemetschek Presentaion @ HackBulgaria
HackBulgaria
•
886 views
The evolution of java script asynchronous calls
Huy Hoàng Phạm
•
34.1K views
Async JavaScript Unit Testing
Mihail Gaberov
•
161 views
Node.js
Mat Schaffer
•
823 views
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
GITS Indonesia
•
134 views
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
POSSCON
•
320 views
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
All Things Open
•
4K views
JavaScript Core
François Sarradin
•
1.6K views
GlueCon 2016 - Threading in JavaScript
Jonathan Baker
•
223 views
Promises are so passé - Tim Perry - Codemotion Milan 2016
Codemotion
•
404 views
Service worker - Offline Web
Bruno Oliveira
•
860 views
Promises look into the async future
slicejs
•
1.1K views
What's New in JavaScript
Dan Cohn
•
31 views
Asynchronous Programming with JavaScript
WebF
•
437 views
Serverless in-action
Assaf Gannon
•
317 views
Going Serverless
Mattias Severson
•
470 views
Playing With Fire - An Introduction to Node.js
Mike Hagedorn
•
1K views
Sufan presentation
Sufanhk
•
28 views
Recently uploaded
Keynote: Two years at the British Library... and counting / Alan Danskin (Bri...
CILIP MDG
17 views
•
33 slides
Nymity Framework: Privacy & Data Protection Update in 7 States
TrustArc
99 views
•
22 slides
Inclusivity and AI: opportunity or threat
Alan Dix
30 views
•
37 slides
TEKART CON 2023
AdedoyinSamuel1
17 views
•
35 slides
Regulating Generative AI - LLMOps pipelines with Transparency
Debmalya Biswas
40 views
•
16 slides
How to Manage Your Offshore Software Development Team Efficiently
Capital Numbers
18 views
•
15 slides
Recently uploaded
(20)
Keynote: Two years at the British Library... and counting / Alan Danskin (Bri...
CILIP MDG
•
17 views
Nymity Framework: Privacy & Data Protection Update in 7 States
TrustArc
•
99 views
Inclusivity and AI: opportunity or threat
Alan Dix
•
30 views
TEKART CON 2023
AdedoyinSamuel1
•
17 views
Regulating Generative AI - LLMOps pipelines with Transparency
Debmalya Biswas
•
40 views
How to Manage Your Offshore Software Development Team Efficiently
Capital Numbers
•
18 views
Improve Employee Experiences on Cisco RoomOS Devices, Webex, and Microsoft Te...
ThousandEyes
•
78 views
BuilderAI Proposal_Malesniak
Michael Lesniak
•
81 views
Jino Clone: Develop a Car Wash Mobile App with Limited Resources
eSiteWorld TechnoLabs Pvt. Ltd.
•
21 views
Roottoo Innovation V24_CP.pdf
roottooinnovation
•
20 views
Accelerating Data Science through Feature Platform, Transformers, and GenAI
FeatureByte
•
117 views
Unleashing the Power of Modern Carpooling Apps, Inspired by BlaBlaCar
Archie Cadell
•
26 views
who we are - values.pptx
LauraGarceran
•
28 views
Microsoft Azure New - Sep 2023
Daniel Toomey
•
28 views
MapInfo Pro v2023: The Next Dimension in Spatial Analytics
Precisely
•
33 views
AI for Da'wah (Da'wah for AI)
Muhammad Angga Muttaqien
•
79 views
Value proposition of SSI tech providers - Self-Sovereign Identity
SSIMeetup
•
126 views
From Ambition to Go Live SWIB.pdf
RichardWallis3
•
60 views
Document Understanding as Cloud APIs and Generative AI Pre-labeling Extractio...
DianaGray10
•
33 views
Scaling out with WordPress
Konstantin Kovshenin
•
44 views
Promise pattern
1.
Promise Pattern for asynchronous
JavaScript Sebastiaan Deckers — 2012 — BeermatesJS Singapore
2.
What is
asynchronous programming? Are we there yet? Are we there yet? Are we there yet? Are we there yet? ...
3.
When do you
use asynchronous programming?
4.
Performance User input,
network I/O (AJAX), computational processing, rendering, ...
5.
KISS
(keep it simple, stupid!) Separation of concerns, Less boilerplate, Focus on business logic
6.
Asynchronous Patterns
Callbacks, Events, Promises
7.
Callbacks $.get('foobar.html', function(data) {
$('.result').html(data); alert('Load was performed.'); });
8.
Problem? ●
Only one callback at a time ● Nested callbacks: turtles all the way down
9.
Events $('a.button') .on('click',
function(event) { // do something... }) .on('click', function(event) { // ... and do something else. });
10.
Problem? ●
Hard to synchronise multiple events ● No standard APIs
11.
Promises
Asynchronous API Provider Business Logic Promise Asynchronous API Provider Asynchronous API Provider
12.
Business Logic (new Promise)
.when(load_asset('maps/lobby.bsp')) .when(load_asset('music/intro.ogg')) .when(choose_name()) .then(function() { // everything loaded, start the game... });
13.
API Providers function load_asset(path)
{ return new Promise(function(deferred) { $.get(path, deferred.done); }); } function choose_name() { var valid = /^[a-zA-Z0-9_]+$/; return new Promise(function(deferred) { $('form').submit(function() { if(valid.test($('.name).val())) deferred.done(); }); }); }
14.
CommonJS
Promise/* http://wiki.commonjs.org/wiki/Promises
15.
The Basics Business Logic:
● when ● then API Provider: ● deferred.done
16.
The Tricks .when().when() //
parallel chaining .then().then() // multiple listeners .asap() // Race condition // Edge cases .deferred.failure(reason) .then(success, error) // Progress tracking .deferred.progress(amount) .then(success, error, progress)