隐式的绑定
如果域正在使用中,则所有新的 EventEmitter
对象(包括流对象、请求、响应等)将在创建时隐式地绑定到活动域。
此外,传给低层事件循环请求的回调(例如 fs.open()
、或其他回调接受的方法)将自动绑定到活动域。
如果它们抛出,则域将捕获错误。
为了防止过多的内存使用,Domain
对象本身没有被隐式地添加为活动域的子域。
如果是这样,则阻止请求和响应对象被正确地垃圾收集就太容易了。
要将 Domain
对象嵌套为父 Domain
的子对象,则必须显式地添加它们。
隐式的绑定路由向 Domain
的 'error'
事件抛出错误和 'error'
事件,但没有在 Domain
上注册 EventEmitter
。
隐式的绑定只处理抛出的错误和 'error'
事件。
If domains are in use, then all new EventEmitter
objects (including
Stream objects, requests, responses, etc.) will be implicitly bound to
the active domain at the time of their creation.
Additionally, callbacks passed to lowlevel event loop requests (such as
to fs.open()
, or other callback-taking methods) will automatically be
bound to the active domain. If they throw, then the domain will catch
the error.
In order to prevent excessive memory usage, Domain
objects themselves
are not implicitly added as children of the active domain. If they
were, then it would be too easy to prevent request and response objects
from being properly garbage collected.
To nest Domain
objects as children of a parent Domain
they must be
explicitly added.
Implicit binding routes thrown errors and 'error'
events to the
Domain
's 'error'
event, but does not register the EventEmitter
on the
Domain
.
Implicit binding only takes care of thrown errors and 'error'
events.