Syncing Async
Upcoming SlideShare
Loading in...5
×
 

Syncing Async

on

  • 167 views

Syncing Async ...

Syncing Async
with Kyle Simpson
Presented on September 17 2014 at
FITC's Web Unleashed Toronto 2014

I bet you think “callback hell” is about function nesting and levels of indentation. Not so much. I bet you’ve heard that Promises replace callbacks. Nope.

We need some clarity on what async flow control is all about in JavaScript. We’ll explore the perils of “Inversion of Control”, and see just what hell that leads us to. Then we’ll talk about promises as “continuation events” for function calls, and abstractions on top of promises that clean up our code. Finally, we’ll see how generators give us synchronous-looking async, and even how we can create cooperative concurrency with coroutines.

Yield those confused async notions and control your flow. I promise we’ll get your thoughts in order.

OBJECTIVE
Learn why async flow control patterns are necessary for JS, why callbacks aren’t sufficient and how promises and generators are the solution.

TARGET AUDIENCE
JS developers

ASSUMED AUDIENCE KNOWLEDGE
Intermediate to advanced JS (3+ years experience).

FIVE THINGS AUDIENCE MEMBERS WILL LEARN
Why our brains reason about code differently than the JS engine does
Why callback hell has much less to do with nesting/indentation than you thought
What inversion of control is all about, and what trust issues it creates for our code
What promises are and why they not only make code easier to reason about, but also solve inversion of control issues
Why generators are even better, and how generators+promises are potentially the best pattern we can achieve thus far

Statistics

Views

Total Views
167
Views on SlideShare
163
Embed Views
4

Actions

Likes
1
Downloads
0
Comments
0

1 Embed 4

https://twitter.com 4

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Syncing Async Syncing Async Presentation Transcript

  • syncing async kyle simpson @getify http://getify.me
  • to get started...
  • parallel vs. async
  • threads
  • event-loop concurrency
  • 123 1234
  • 1 1 2 23 34 done! done!
  • async patterns
  • callbacks == continuations
  • callbacks got problems 2 major ^
  • “callback hell”
  • still “callback hell”
  • inversion of control
  • trust: 1. not too early 2. not too late 3. not too many times 4. not too few times 5. no lost context 6. no swallowed errors ...
  • nested callbacks are not reasonable
  • we write
  • many steps such sync very wow
  • we think
  • js thinks
  • sync-looking async synchronous sequential blocking
  • hell is callbacks -Sartre
  • promise: future value
  • promise: “completion” event
  • promises: 1. only resolved once 2. either success OR error 3. messages passed/kept 4. exceptions become errors 5. immutable once resolved
  • uninversion of control
  • steps
  • promise: flow control
  • scenario: load files in parallel, render in order, but ASAP
  • cool story, bro. but...
  • scenario: timeout of a promise
  • blog.getify.com/promises-part-1/ github.com/getify/native-promise-only
  • promise abstractions
  • sequence = series of automatically chained promises
  • async + sequence = asynquence github.com/getify/asynquence
  • remember? load files in parallel, render in order, but ASAP
  • promises without all the fuss
  • gimme moar sync
  • ES6 generators davidwalsh.name/es6-generators
  • yield promises generator + promises
  • what about pre-ES6 browsers?
  • transpiled ES5 “generators” facebook.github.io/regenerator/
  • ~ES7 async ? github.com/lukehoban/ecmascript-asyncawait
  • CSP-like concurrency
  • .done() chuckle, chuckle
  • thx! kyle simpson @getify http://getify.me