Transcript
Page 1: Thread Local Storage Execution Contexts in JavaScript with ZoneJS

Your Cloud.Your Business.

ZoneJS (Thread/JavaScript/etc.) Jeremy Likness Principal Architect @JeremyLikness

Page 2: Thread Local Storage Execution Contexts in JavaScript with ZoneJS

www.ivision.com

Page 3: Thread Local Storage Execution Contexts in JavaScript with ZoneJS

TODAY’S AGENDA

1. Background JavaScript’s event loop and where zone fits in

2. Example Example of an app without Zone

3. Zone Deep Dive Hands on demos of Zone capabilities

4. Q&A Questions (hopefully answers!)

Page 4: Thread Local Storage Execution Contexts in JavaScript with ZoneJS

BACKGROUND

Page 5: Thread Local Storage Execution Contexts in JavaScript with ZoneJS

BACKGROUND

• For all practical purposes, JavaScript runs on a single thread• There is always a global context, but to avoid collisions and

enable modular code it is recommended you avoid using it• JavaScript executes in an event loop. Keyboard, mouse, and

network events are all placed in a queue.• Timers simply place callbacks in the queue with restrictions (i.e.

don’t pull this for another 2 seconds)• The event loop simply pulls the next entry in the queue and

processes it

Page 6: Thread Local Storage Execution Contexts in JavaScript with ZoneJS

The Event Loop

Grab Event

Check for

Handler

Execute Handler

Mouse Click

Text Input

Timer Callback

Keyboard Mouse Network Timer Events

Event loop

Event queue

Page 7: Thread Local Storage Execution Contexts in JavaScript with ZoneJS

Why Zone?

• Each pass of the event loop can be considered a turn • You may want to carry context within a turn• Plugging into turns enables instrumentation and metrics • Zone does this at a global level so you don’t have to change

existing code• A turn has the following lifecycle:

Enqueue Before During After Dequeue

Page 8: Thread Local Storage Execution Contexts in JavaScript with ZoneJS

DEMO: Zone in Action

Page 9: Thread Local Storage Execution Contexts in JavaScript with ZoneJS

Questions?

Source for this deckhttps://github.com/JeremyLikness/LearnZoneJs

Running example for this deckhttp://jeremylikness.github.io/LearnZoneJs

Get Zonehttps://github.com/angular/zone.js

Jeremy Likness, Principal Architect @JeremyLikness


Top Related