SlideShare a Scribd company logo
PROMISES/A+
WAS BORN
BOOM!
HI, I’M @DOMENIC
The JavaScript community’s
greatest strength
is that we turn tiny primitives into
powerful patterns.
But it is also
our greatest weakness.
The Promises/A+ story is a story wherein
the community overcame this weakness.
Let’s talk about async.
CONTINUATION PASSING STYLE
var fileName = "data.txt";
fs.readFile(fileName, function (err, data) {
// ...
});
CPS is easy.
But it is not simple.
CPS traps you in the Turing Tarpit.
return and throw, where did you go!
ENTER PROMISES
 Joule and E’s promises
 Java’s java.util.concurrent.Future
 Python’s Twisted deferreds and PEP-3148 futures
 F#’s Async<T>
 .NET’s Task<T>
 C++11’s std::future
 Dart’s Future<T>
 JavaScript’s Promises/A+
The point of promises is simple:
to give you back async versions of
return and throw.
function* someNumbers() {
console.log("A");
yield 1;
console.log("B");
yield 2;
console.log("C");
yield 3;
console.log("D");
}
var iterator = someNumbers();
console.log(iterator.next()); // "A", { value: 1, done: false }
console.log(iterator.next()); // "B", { value: 2, done: false }
console.log(iterator.next()); // "C", { value: 3, done: false }
console.log(iterator.next()); // "D", { value: undefined, done: true }
http://jsbin.com/eqamor/1/edit
Q.async(function* () {
$("#loading").text("Loading...").fadeIn();
try {
var repoEvents = yield getRepoEvents("kriskowal", "q");
updateUI(repoEvents);
$("#loading").text("Loaded!");
} catch (e) {
$("#loading").text("Error loading data: " + e.message);
} finally {
yield Q.delay(5000);
$("#loading").fadeOut();
}
})();
http://jsbin.com/igimow/1/edit
As a bonus, we get time travel:
promises are objects representing
objects from a different time.
expect(promise).to.eventually.deep.equal(["zomg", "jsconf!"]);
Boom! Promises/A+ Was Born
// ES5
userPromise
.get("repos").get(0)
.get("commitHistory")
.invoke("toHTML")
.then(displayInUI)
.done();
// ES6
const html = yield userPromise.repos[0].commitHistory.toHTML();
displayInUI(html);
Boom! Promises/A+ Was Born
// ES5
userPromise
.get("repos").get(0)
.get("commitHistory")
.invoke("toHTML")
.then(displayInUI)
.done();
// ES6
const html = yield userPromise.repos[0].commitHistory.toHTML();
displayInUI(html);
var Connection = require("q-connection");
var remote = Connection(port);
// a promise for the remote user object!
var userPromise = remote.invoke("getUser", "domenic");
 Web Socket
 Web Worker
 Message Port
https://github.com/kriskowal/q-connection/
PROMISES IN JAVASCRIPT
The path to Promises/A+ has been
long and treacherous.
It all started with CommonJS Promises/A
https://groups.google.com/d/msg/commonjs/6T9z75fohDk/U_0Gl9fPJxsJ
Enter $.Deferred
http://bugs.jquery.com/ticket/11010
Boom! Promises/A+ Was Born
Not Again!!
https://github.com/emberjs/ember.js/pull/1406
Horrible lies!
Boom! Promises/A+ Was Born
https://gist.github.com/domenic/3889970
https://github.com/domenic/promise-tests
https://gist.github.com/briancavalier/eb5fc157825a170c9957
http://promisesaplus.com
ok, so what?
https://github.com/promises-aplus/promises-spec/blob/master/implementations.md
http://dom.spec.whatwg.org/#futures
And if you don’t have an API you might
as well set up some Futures. Just in case.
http://wiki.ecmascript.org/lib/exe/fetch.php?media=strawman:roadmap.pdf
… what just happened?
OPEN SPECIFICATION DEVELOPMENT
What made the Promises/A+ effort work so well?
 The cause
 The people
 The code
 The contract
 The setting
the cause:
bringing sane asynchronicity to JS
the people:
a strong and cooperative community
the code:
existing convergent and widely-loved solutions
the contract:
a small core for interoperation via standardization
the setting:
GitHub
An open standard for sound, interoperable JavaScript
promises—by implementers, for implementers.
With these ingredients, you can extend the web forward.
http://yehudakatz.com/2013/05/21/extend-the-web-forward/
THANKS!
promisesaplus.com
@promisesaplus

More Related Content

What's hot

Promise pattern
Promise patternPromise pattern
Promise pattern
Sebastiaan Deckers
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
L&T Technology Services Limited
 
Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascript
Łukasz Kużyński
 
Asynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsAsynchronous programming done right - Node.js
Asynchronous programming done right - Node.js
Piotr Pelczar
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJS
Sylvain Zimmer
 
JavaScript Promise
JavaScript PromiseJavaScript Promise
JavaScript Promise
Joseph Chiang
 
Javascript Promises/Q Library
Javascript Promises/Q LibraryJavascript Promises/Q Library
Javascript Promises/Q Library
async_io
 
Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.js
cacois
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
jnewmanux
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Domenic Denicola
 
Callbacks and control flow in Node js
Callbacks and control flow in Node jsCallbacks and control flow in Node js
Callbacks and control flow in Node js
Thomas Roch
 
Java Script Promise
Java Script PromiseJava Script Promise
Java Script Promise
Alok Guha
 
JavaScript promise
JavaScript promiseJavaScript promise
JavaScript promise
eslam_me
 
A Gentle Introduction to Event Loops
A Gentle Introduction to Event LoopsA Gentle Introduction to Event Loops
A Gentle Introduction to Event Loops
deepfountainconsulting
 
Getting Comfortable with JS Promises
Getting Comfortable with JS PromisesGetting Comfortable with JS Promises
Getting Comfortable with JS Promises
Asa Kusuma
 
Practical JavaScript Promises
Practical JavaScript PromisesPractical JavaScript Promises
Practical JavaScript Promises
Asa Kusuma
 
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Kenji Tanaka
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
Domenic Denicola
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is here
Sebastiano Armeli
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
Wim Godden
 

What's hot (20)

Promise pattern
Promise patternPromise pattern
Promise pattern
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascript
 
Asynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsAsynchronous programming done right - Node.js
Asynchronous programming done right - Node.js
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJS
 
JavaScript Promise
JavaScript PromiseJavaScript Promise
JavaScript Promise
 
Javascript Promises/Q Library
Javascript Promises/Q LibraryJavascript Promises/Q Library
Javascript Promises/Q Library
 
Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.js
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Callbacks and control flow in Node js
Callbacks and control flow in Node jsCallbacks and control flow in Node js
Callbacks and control flow in Node js
 
Java Script Promise
Java Script PromiseJava Script Promise
Java Script Promise
 
JavaScript promise
JavaScript promiseJavaScript promise
JavaScript promise
 
A Gentle Introduction to Event Loops
A Gentle Introduction to Event LoopsA Gentle Introduction to Event Loops
A Gentle Introduction to Event Loops
 
Getting Comfortable with JS Promises
Getting Comfortable with JS PromisesGetting Comfortable with JS Promises
Getting Comfortable with JS Promises
 
Practical JavaScript Promises
Practical JavaScript PromisesPractical JavaScript Promises
Practical JavaScript Promises
 
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is here
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 

Viewers also liked

ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
Wojciech Dzikowski
 
The jsdom
The jsdomThe jsdom
The jsdom
Domenic Denicola
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
hesher
 
ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
Domenic Denicola
 
Lecture 2: ES6 / ES2015 Slide
Lecture 2: ES6 / ES2015 SlideLecture 2: ES6 / ES2015 Slide
Lecture 2: ES6 / ES2015 Slide
Kobkrit Viriyayudhakorn
 
Real World Windows 8 Apps in JavaScript
Real World Windows 8 Apps in JavaScriptReal World Windows 8 Apps in JavaScript
Real World Windows 8 Apps in JavaScript
Domenic Denicola
 
Creating Truly RESTful APIs
Creating Truly RESTful APIsCreating Truly RESTful APIs
Creating Truly RESTful APIs
Domenic Denicola
 
The Final Frontier
The Final FrontierThe Final Frontier
The Final Frontier
Domenic Denicola
 
Client-Side Packages
Client-Side PackagesClient-Side Packages
Client-Side Packages
Domenic Denicola
 
Introducing Razor - A new view engine for ASP.NET
Introducing Razor - A new view engine for ASP.NET Introducing Razor - A new view engine for ASP.NET
Introducing Razor - A new view engine for ASP.NET
Shiju Varghese
 
Razor and the Art of Templating
Razor and the Art of TemplatingRazor and the Art of Templating
Razor and the Art of Templating
Jess Chadwick
 
Views
ViewsViews
Views
Eyal Vardi
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
Solution4Future
 
JavaScript on the Desktop
JavaScript on the DesktopJavaScript on the Desktop
JavaScript on the Desktop
Domenic Denicola
 
Keeping Promises
Keeping PromisesKeeping Promises
Keeping Promises
David Harkins
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And Navigation
Eyal Vardi
 
Angular 2 NgModule
Angular 2 NgModuleAngular 2 NgModule
Angular 2 NgModule
Eyal Vardi
 
Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0
Eyal Vardi
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
Eyal Vardi
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
Eyal Vardi
 

Viewers also liked (20)

ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
 
The jsdom
The jsdomThe jsdom
The jsdom
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
 
ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
 
Lecture 2: ES6 / ES2015 Slide
Lecture 2: ES6 / ES2015 SlideLecture 2: ES6 / ES2015 Slide
Lecture 2: ES6 / ES2015 Slide
 
Real World Windows 8 Apps in JavaScript
Real World Windows 8 Apps in JavaScriptReal World Windows 8 Apps in JavaScript
Real World Windows 8 Apps in JavaScript
 
Creating Truly RESTful APIs
Creating Truly RESTful APIsCreating Truly RESTful APIs
Creating Truly RESTful APIs
 
The Final Frontier
The Final FrontierThe Final Frontier
The Final Frontier
 
Client-Side Packages
Client-Side PackagesClient-Side Packages
Client-Side Packages
 
Introducing Razor - A new view engine for ASP.NET
Introducing Razor - A new view engine for ASP.NET Introducing Razor - A new view engine for ASP.NET
Introducing Razor - A new view engine for ASP.NET
 
Razor and the Art of Templating
Razor and the Art of TemplatingRazor and the Art of Templating
Razor and the Art of Templating
 
Views
ViewsViews
Views
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
 
JavaScript on the Desktop
JavaScript on the DesktopJavaScript on the Desktop
JavaScript on the Desktop
 
Keeping Promises
Keeping PromisesKeeping Promises
Keeping Promises
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And Navigation
 
Angular 2 NgModule
Angular 2 NgModuleAngular 2 NgModule
Angular 2 NgModule
 
Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
 

Similar to Boom! Promises/A+ Was Born

Asynchronous development in JavaScript
Asynchronous development  in JavaScriptAsynchronous development  in JavaScript
Asynchronous development in JavaScript
Amitai Barnea
 
ECMAScript 2015
ECMAScript 2015ECMAScript 2015
ECMAScript 2015
Sebastian Pederiva
 
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
PROIDEA
 
Sane Async Patterns
Sane Async PatternsSane Async Patterns
Sane Async Patterns
TrevorBurnham
 
TPSE Thailand 2015 - Rethinking Web with React and Flux
TPSE Thailand 2015 - Rethinking Web with React and FluxTPSE Thailand 2015 - Rethinking Web with React and Flux
TPSE Thailand 2015 - Rethinking Web with React and Flux
Jirat Kijlerdpornpailoj
 
The Atmosphere Framework
The Atmosphere FrameworkThe Atmosphere Framework
The Atmosphere Framework
jfarcand
 
ESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. NowESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. Now
Krzysztof Szafranek
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
Sven Haiges
 
Parse Advanced
Parse AdvancedParse Advanced
Parse Advanced
Tushar Acharya
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
David Padbury
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
ES6 - JavaCro 2016
ES6 - JavaCro 2016ES6 - JavaCro 2016
ES6 - JavaCro 2016
Nenad Pecanac
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
Sigma Software
 
Advanced I/O in browser
Advanced I/O in browserAdvanced I/O in browser
Advanced I/O in browser
Eugene Lazutkin
 
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
Javantura v3 - ES6 – Future Is Now – Nenad PečanacJavantura v3 - ES6 – Future Is Now – Nenad Pečanac
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Designing a JavaFX Mobile application
Designing a JavaFX Mobile applicationDesigning a JavaFX Mobile application
Designing a JavaFX Mobile application
Fabrizio Giudici
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Pavlo Baron
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
Abbas Raza
 
Promises look into the async future
Promises look into the async futurePromises look into the async future
Promises look into the async future
slicejs
 

Similar to Boom! Promises/A+ Was Born (20)

Asynchronous development in JavaScript
Asynchronous development  in JavaScriptAsynchronous development  in JavaScript
Asynchronous development in JavaScript
 
ECMAScript 2015
ECMAScript 2015ECMAScript 2015
ECMAScript 2015
 
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
 
Sane Async Patterns
Sane Async PatternsSane Async Patterns
Sane Async Patterns
 
TPSE Thailand 2015 - Rethinking Web with React and Flux
TPSE Thailand 2015 - Rethinking Web with React and FluxTPSE Thailand 2015 - Rethinking Web with React and Flux
TPSE Thailand 2015 - Rethinking Web with React and Flux
 
The Atmosphere Framework
The Atmosphere FrameworkThe Atmosphere Framework
The Atmosphere Framework
 
ESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. NowESCMAScript 6: Get Ready For The Future. Now
ESCMAScript 6: Get Ready For The Future. Now
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
Parse Advanced
Parse AdvancedParse Advanced
Parse Advanced
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
ES6 - JavaCro 2016
ES6 - JavaCro 2016ES6 - JavaCro 2016
ES6 - JavaCro 2016
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
 
Advanced I/O in browser
Advanced I/O in browserAdvanced I/O in browser
Advanced I/O in browser
 
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
Javantura v3 - ES6 – Future Is Now – Nenad PečanacJavantura v3 - ES6 – Future Is Now – Nenad Pečanac
Javantura v3 - ES6 – Future Is Now – Nenad Pečanac
 
Designing a JavaFX Mobile application
Designing a JavaFX Mobile applicationDesigning a JavaFX Mobile application
Designing a JavaFX Mobile application
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Promises look into the async future
Promises look into the async futurePromises look into the async future
Promises look into the async future
 

More from Domenic Denicola

ES6 in Real Life
ES6 in Real LifeES6 in Real Life
ES6 in Real Life
Domenic Denicola
 
Streams for the Web
Streams for the WebStreams for the Web
Streams for the Web
Domenic Denicola
 
After Return of the Jedi
After Return of the JediAfter Return of the Jedi
After Return of the Jedi
Domenic Denicola
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
Domenic Denicola
 
How to Win Friends and Influence Standards Bodies
How to Win Friends and Influence Standards BodiesHow to Win Friends and Influence Standards Bodies
How to Win Friends and Influence Standards Bodies
Domenic Denicola
 
The Extensible Web
The Extensible WebThe Extensible Web
The Extensible Web
Domenic Denicola
 
Unit Testing for Great Justice
Unit Testing for Great JusticeUnit Testing for Great Justice
Unit Testing for Great Justice
Domenic Denicola
 
Understanding the Node.js Platform
Understanding the Node.js PlatformUnderstanding the Node.js Platform
Understanding the Node.js Platform
Domenic Denicola
 

More from Domenic Denicola (8)

ES6 in Real Life
ES6 in Real LifeES6 in Real Life
ES6 in Real Life
 
Streams for the Web
Streams for the WebStreams for the Web
Streams for the Web
 
After Return of the Jedi
After Return of the JediAfter Return of the Jedi
After Return of the Jedi
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
 
How to Win Friends and Influence Standards Bodies
How to Win Friends and Influence Standards BodiesHow to Win Friends and Influence Standards Bodies
How to Win Friends and Influence Standards Bodies
 
The Extensible Web
The Extensible WebThe Extensible Web
The Extensible Web
 
Unit Testing for Great Justice
Unit Testing for Great JusticeUnit Testing for Great Justice
Unit Testing for Great Justice
 
Understanding the Node.js Platform
Understanding the Node.js PlatformUnderstanding the Node.js Platform
Understanding the Node.js Platform
 

Recently uploaded

HTTP Adaptive Streaming – Quo Vadis (2024)
HTTP Adaptive Streaming – Quo Vadis (2024)HTTP Adaptive Streaming – Quo Vadis (2024)
HTTP Adaptive Streaming – Quo Vadis (2024)
Alpen-Adria-Universität
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
shanthidl1
 
Observability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetryObservability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetry
Eric D. Schabell
 
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALLBLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
Liveplex
 
What's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdfWhat's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdf
SeasiaInfotech2
 
AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)
apoorva2579
 
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating AppsecGDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
James Anderson
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
HackersList
 
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & SolutionsMYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
Linda Zhang
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
Enterprise Wired
 
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
amitchopra0215
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
Matthew Sinclair
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
BookNet Canada
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
huseindihon
 
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdfWhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
ArgaBisma
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
Emerging Tech
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
What's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptxWhat's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptx
Stephanie Beckett
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
Yevgen Sysoyev
 
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design ApproachesKnowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Earley Information Science
 

Recently uploaded (20)

HTTP Adaptive Streaming – Quo Vadis (2024)
HTTP Adaptive Streaming – Quo Vadis (2024)HTTP Adaptive Streaming – Quo Vadis (2024)
HTTP Adaptive Streaming – Quo Vadis (2024)
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
 
Observability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetryObservability For You and Me with OpenTelemetry
Observability For You and Me with OpenTelemetry
 
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALLBLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
BLOCKCHAIN FOR DUMMIES: GUIDEBOOK FOR ALL
 
What's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdfWhat's Next Web Development Trends to Watch.pdf
What's Next Web Development Trends to Watch.pdf
 
AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)
 
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating AppsecGDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
 
How Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdfHow Social Media Hackers Help You to See Your Wife's Message.pdf
How Social Media Hackers Help You to See Your Wife's Message.pdf
 
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & SolutionsMYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
 
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
 
find out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challengesfind out more about the role of autonomous vehicles in facing global challenges
find out more about the role of autonomous vehicles in facing global challenges
 
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdfWhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
WhatsApp Image 2024-03-27 at 08.19.52_bfd93109.pdf
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
 
What's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptxWhat's New in Copilot for Microsoft365 May 2024.pptx
What's New in Copilot for Microsoft365 May 2024.pptx
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
 
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design ApproachesKnowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
 

Boom! Promises/A+ Was Born

Editor's Notes

  1. And I’m happy to be here.
  2. The most amazing example of this is ES5 module systems.But we see this over and over, from modules to classes to callbacks to streams to events to something as small as chainable APIs…We use function and object to cobble together amazing applications and propagate the wisdom we used to create them.Sure, it’s a a bunch of hacks, but they’re practical ones: and that’s what JavaScript’s always about.
  3. We become prideful in our ability to shape worlds out of the primordial stardust of functionWe get stuck in our patterns, saying that because a certain thing is easiest to express in terms of function, it is therefore bestMore generally, we assume that the best ideas are those that express naturally in JS, and refuse to learn from other languages.
  4. The async programming revolution has been brewing for a while.While JS made it popular, because JS is popular, it’s not the first place these ideas have been explored.Unfortunately, JS’s initial async APIs were designed as part of the DOM, and we all know how …. pleasant …. DOM APIs are.
  5. Even Node.js was not able to escape the DOM’s legacy.It did decide on a common signature for its callbacks---mostly.But it never took a step back and surveyed the landscape of design options for asynchronous programming.It fell into the “moar functions” trap, and did literally the simplest thing.
  6. CPS is the easiest thing to do in JavaScript, where function is your favorite tool. You reach out and it’s right there.You need to do an async operation? Just stuff the rest of your code into a function! Everyone can do that! Anyone who can’t is clearly a JavaScript noob (not kidding!)But it is not simple. What do I mean by that…
  7. Why is CPS complex? Because it traps you into the Turing Tarpit. The idea that yes, indeed, JS is Turing complete, so we can build whatever system we want in it.This is usually applied to things like reinventing large parts of the web platform using JS, because HTML and CSS aren’t flexible enough. But when you end up using CPS, this is exactly what happens to async programming.It forces you to reinvent the basic features of the language, features like returning a value or throwing an error, in terms of function conventions.If you think about it, you have essentially reinvented the call stack!You end up using combinator functions tying together these callback functions just to express what was already in your language!And sure, it’s not “hard”---it is, in fact, easy. Everyone can do this, and everyone does. But it’s not simple.This kind of complexity has all kind of cognitive and maintenance burdens, as you try to understand the gymnastics your intertwined function combinators are forcing you through. Did someone accidentally call the callback twice? What’s the value of that counter I use for doing things in parallel? Did I remember to pass up any errors to my caller? I don’t know, and I don’t want to know! I just want an asynchronous function call; I don’t care how!
  8. An asynchronous function call.When you see something like this, generally it means one of two things:An idea so good that everyone had to copy itConvergent evolution on a natural solutionPromises are a bit of both.I don’t really want to show you how to use promises in JavaScript. Read some blogs for that. Instead I want to make you understand why you should use promises in JavaScript.
  9. Instead of thrashing wildly in the Turing Tarpit, only to sink further, we turn our attention toward an abstraction that can bring us back into the semantics of JavaScript.We create an async call stack, regaining all the semantics from our language and integrating well with synchronous return/throw.In this way promises are fundamentally simple, allowing composability in the same way our normal language constructs do. You can compose asynchronous functions without gymnastics, without having to entangle your concern of calling the function with the function’s concern of doing asynchronous work.There’s a rather drastic demonstration of this available to you behind some V8 flags. Let me introduce you to generators…
  10. The other major thing about promises is…
  11. Not only do we get back our language semantics of try/throw, we also get as a bonus these first-class objects representing asynchronous operations, i.e. representing objects from a different time.You can see an example of how powerful this is, where we do unit test assertions on our promise, about what its value will eventually be. This is implemented today in a library I’ve created.
  12. Here’s some code the that uses promises.Note that this is beyond Promises/A+’s `then` interface. But the basic idea is that we have a promise for a user, then we call this method to get a promise for its “repos” property. (Etc.)Just pointing out that with ES6 proxies, we can make this a lot nicer.So that’s kind of cool, it’s some nice sugar over a bunch of traditional promise code. And of course with ES6 it’s delightful. But…
  13. Everything here takes on a whole new meaning!Consider this in light of traditional “remote object” systems. They usually fall down in various ways, for example:They would translate this into a series of requests, e.g. first for the repos, then for the 0th property, etc.Or they would try to maintain a local copy of the remote object, which leads to synchronization problems and complex serialization and rehydration approaches, deciding when to do things locally and when remotely, and how to synchronize them.But with promises as the abstraction, just like we normally use them to co-locate our operations in time, we can also use them to co-locate in space. We can “pipeline” these messages from one side to the other, retrieving only the ultimately-desired result (in this case some server-rendered HTML).
  14. How do you get a userPromise? Use Q-ConnectionQ-Connection has the whole promise pipelining thing. Other approaches to promises representing remote objects can be found in a framework like OasisJS.
  15. That brings us to the end of our “promises are really cool” portion. Now I want to talk about that story I promised you earlier, where as a community we overcame our greatest weakness in order to push promises to the level they’re at today.
  16. Actually, it all started with Dojo, as did pretty much everything apparently.Promises/A captured the core idea of promises from other languagesBut: it was underspecified, missing key features, and written in prose that was easy to misinterpretOne of the consequences of this was… jQuery $.Deferred.
  17. … yeah. They missed the whole async/sync parallel thing. They failed Promises/A reading comprehension.
  18. Whatever. I can do my own thing. I tried.But I swore a solemn vow on the grave of the dead callbacks I replaced … I’M NOT GOING TO LET THIS HAPPEN AGAIN!
  19. At the bottom of the gist, I wanted to end on a positive note, so I said I would produce a Promises/A test suite, and a few hours later I did.At this point Yehuda got in touch, RSVP.js
  20. And this time, we made a test suite!
  21. It turns out that when you write a clear and thoughtful specification of something people have been implementing haphazardly for a while, and accompany it with a thorough test suite, people really like to implement that spec.
  22. We’ve ended up with over thirty implementations, with new ones streaming in every day.Indeed, we’ve ended up with ones in ActionScript 3, Python, and Objective C! O_oWhat’s wonderful is that, because Promises/A+ only specifies the core unit of interoperability---each implementation’s `then` method---anyone can build libraries that consume promises from any implementation. This is key!
  23. Even the DOM spec authors wanted to get in on this Promises/A+-implementing action! And now we have… “DOM Futures”. O_o.But seriously, promises are now in the DOM! And there’s been major work throughout the WHATWG and W3C to encourage the use of “futures” in upcoming APIs. In fact…
  24. So that’s that…
  25. Somehow, Promises/A+ has become the starting point for any conversation about promises in JavaScript.How did Promises/A+ end up supplanting Promises/A in mindshare so drastically?Why am I getting weekly queries about whether jQuery will fix their promises implementation to conform to us? (jQuery! Think of how many users that has!)How did we go from some nerd rage over a pull request, to a specification that ended up influencing the DOM and possibly even ES7?How did a bunch of implementers congregating on GitHub, just doing our own thing, end up influencing the WHATWG and TC39?
  26. The answer to this question, of “What made the Promises/A+ effort work so well?” boils down to a few principles of what I like to call “open specification development.”
  27. This is the stuff we talked about earlier.You can’t build a specification like this around things nobody cares about. You need to solve real problems, and you need to solve them with coherent solutions.
  28. Led by Brian CavalierWe all cared deeply about these issues, but were not too far apart in our goalsWe were willing to compromise (Brian notably enforcing asynchronicity in When.js 2.0)
  29. The biggest reason harks back to what I was saying at the beginning. We harnessed JS developers greatest strength, how we had already built promises from the fundamental primitives available to us. We’d been doing this for literally years before banding together. Implementations like Q and when were in widespread use, and Yehuda’s RSVP.js was starting to make ripples. We all had the experience and knowledge to know what worked and what didn’t. In short, code before prose.
  30. All we specified was the `then` method---because that was enough!In contrast, we could have been fighting over which library’s API, with all its glorious surface area and helper methods, became “standard.”Heck, we didn’t even specify how to create a promise!This is why I like to say that DOMFuture is a Promises/A+ promise implementation, even though it itself is a spec: it, like Q or when, builds on the core interoperable `then` method in order to create a larger surface area for its consumers to adopt (in this case the browsers).
  31. GitHub is where we work and play, as a communityIt encourages easy forking, pull requests, and discussionIt has great Markdown integration, which is notable since Markdown diffs are very easy to readRevision history and past discussions are easily viewable and searchable, allowing new participants to jump in to the standards process just like they would with a code projectExperimental spikes can take place in branchesEven the W3C and WHATWG are starting to see this, but they haven’t made the complete transition, with their high reliance on archaic mailing lists and their hard-to-read HTML diffs
  32. At this point I want to stop and reflect on the Promises/A+ tagline. We spent some time on this, but in the end I think it’s perfect: we mean every word.We’re open: we do everything on GitHub, out in the open.We’re sound: that’s our cause. We’re interoperable: that’s our contract. And it’s by implementers and for implementers, reflecting our commitment to build on existing code and to leverage the strength of the promise community.So if you have all these “open specification development” ingredients…
  33. With this phrase, I’m referring to a specific philosophy which has recently been championed by the W3C’s newly-reformed Technical Architecture Group, most prominently by the efforts of Yehuda Katz, Alex Russell, and Brian Kardell.The essential idea is to build the web platform, not on magic browser APIs, but on composable JavaScript primitives.This leads to exactly the kind of virtuous cycle that Promises/A+ has exhibited: the community creates an API, competes and refines it together, reaches a convergence, and eventually the common primitives get incorporated into the web platform itself.