Slide 1

Slide 1 text

A promise is a Promise Sync events without the Nasty Hacks™ David Iglesias Senior Engineer (Front-end Framework) [ twitter | speakerdeck ].com/ditman

Slide 2

Slide 2 text

Event-driven code class PriceComparator { - providers = [ ProvA, ProvB, ProvC, ... ]; - handleProviderDone(provider, price) { // @todo store the price... } + computePrice (param1, param2, param3) { foreach (providers as provider) { provider.on('done', handleProviderDone); provider.computePrice(param1, param2, param3); } // @todo When all providers are done, show them } }

Slide 3

Slide 3 text

● Event listeners must be subscribed before the events are fired ● Knowing when all "providers" are done is hard not straightforward Problems / hard things Naïve solutions turn into Nasty Hacks™

Slide 4

Slide 4 text

● Events with memory ○ They remember being fired ● Composed of 2 parts ○ Promise (handles event subscriptions) ○ Resolver (decides if the promise was success / fail) ● Synchronization mechanisms ○ all, any, some, chain ... Deferred to the rescue! (when.js) ...and they have been around since the '70s!

Slide 5

Slide 5 text

CC Photo by striatic

Slide 6

Slide 6 text

● Late subscription ○ Subscribe to an event seconds after it's been fired ● Synchronization ○ Synchronize 100 slowness providers Examples

Slide 7

Slide 7 text

We're hiring! (of course!) Talk to us! We'll be around! Shameless plug: Thanks! speakerdeck.com/ditman @ditman [email protected]