• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Domains!
 

Domains!

on

  • 4,119 views

Domains were added to Node.js in 0.8, but their use and workings have been a relative mystery. In short, domains are a structured way of reacting to uncaught exceptions; for example, when creating an ...

Domains were added to Node.js in 0.8, but their use and workings have been a relative mystery. In short, domains are a structured way of reacting to uncaught exceptions; for example, when creating an HTTP server, you can use domains to send 500 errors when exceptions occur instead of crashing your server. This talk will go over what domains are, how to use them, and some of the subtleties behind how they work.

Statistics

Views

Total Views
4,119
Views on SlideShare
3,865
Embed Views
254

Actions

Likes
7
Downloads
15
Comments
2

5 Embeds 254

https://twitter.com 229
http://eventifier.co 17
http://storify.com 4
http://192.168.0.108 3
https://storify.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

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

12 of 2 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Opening story: GothamJS, diving into AngularJS code.
  • I work here at Lab49!
  • The first of these, you handle yourself.The second, by design, re-throws the error if there are no listeners for it.The third, since we’re almost always inside a callback, can’t bubble up the call stack; callbacks reset the call stack, so they hit the top of that call stack pretty quickly.—If we were in a browser, those would hit window.onerror.
  • (On switch back) How can we fix this??
  • Let’s build our own “domains” to track error sources!
  • I dug into the source code, and figured out how domains work. This is basically it.
  • I dug into the source code, and figured out how domains work. This is basically it.
  • Since we’ve got this working for everything else, might as well try to make callbacks a bit easier to use.
  • All callbacks you give to Node.js’s code pass through here.Either directly, from C++ code which directly calls MakeCallback to execute your callbackOr indirectly, via a convoluted chain inside src/node.js that ends up in process._makeCallback.
  • To understand how this gives us the power we need, let’s take a step back and see how the domain object themselves work.
  • The moment you start using domains all this gets switched out from under you. process._setupDomainUse()BUT: wrapping in enter()/exit() is just the setup. enter() and exit() do literally nothing besides setting the active domain. The magic takes place in our next chapter:

Domains! Domains! Presentation Transcript