Skip to main content

Module domain

Module domain 

Source
Expand description

Node domain module (deprecated in Node, implemented here with its real error-trapping semantics). A Domain is an EventEmitter (same @@native + @@on/@@once shape as events/net) whose defining behaviour is domain.run(fn): it runs fn and, if fn throws, emits the domain’s 'error' event with the thrown value instead of propagating the throw.

Scope of the port: .run/.bind/.intercept genuinely trap synchronous throws from the function they wrap and route them to 'error'. What is NOT wired is Node’s implicit interception of errors emitted by emitters passed to .add() — node-js has no per-emitter active-domain hook, so .add()/ .remove() only track membership (best-effort) and do not auto-forward those emitters’ 'error' events. Only code run through .run/.bind/.intercept is actually protected. .enter()/.exit() maintain a thread-local domain stack whose top is exposed as domain.active.

Constants§

DOMAIN_METHODS
Instance methods carried by a Domain beyond the shared EventEmitter surface (which instance_has_method adds via the emitter set).
METHODS
Module-level methods (require('domain').create()).

Functions§

call
require('domain') module dispatch.
constant
domain.active — the current (top-of-stack) domain, or null.
construct
new domain.Domain() (Node prefers domain.create(), but the constructor exists).
instance_call
new_domain
A fresh Domain (emitter object tagged "Domain"), carrying a hidden @@members array for .add/.remove bookkeeping.