es6 generators

(they rule)





Gerred Dillon
t: @justicefries
g: gerred
http://www.gerred.com

Protectwise - we're hiring!


WebGL
Canvas
SVG
D3
Backbone
React
ES6 Harmony
Node

Go

Agenda

  • Current state of async code
  • Why synchronous?
  • Intro to Generators
  • Generators - Part 1
    • Iteration
    • Lazy Sequences
  • Generators - Part 2
    • Flow Control
    • Channels
    • Web Frameworks
  • Q&A

javascript

an asynchronous history


Callbacks
Events
Promises

still spaghetti hell all the way down



why synchronous (looking)?



Go
Erlang
ES6 Generators
(and more!)

Harmony Generators


"First-class coroutines, represented as objects encapsulating suspended execution contexts (i.e., function activations). Prior art: Python, Icon, Lua, Scheme, Smalltalk."
- Harmony Generators Proposal

Harmony Generators



Allows suspension of a function's execution
until resolved - everything else outside of that
execution continues.

Compatibility


Chrome - 30-33 with experimental JS flag
Firefox >= 25  (had since 2 but standardized)
Node >= 0.11 w/ --harmony option

API crash course



Generators - Part 1

Lazy Sequences
Infinite Iteration



Generators - Part 2

Flow Control
Co
task.js
Koa

Koa




Minimalistic web framework
Spiritual successor to Express
Generator based, all the way down

Channels


Go-style concurrency in JavaScript

Handling of events

Potentially more powerful than 
promise-based generator implementations

Thanks!


Gerred Dillon
http://www.gerred.com
@justicefries
github: gerred

Resources:

Es6 Generators

By Gerred Dillon