11/*
2- * Copyright (C)2014-2020 Haxe Foundation
2+ * Copyright (C)2014-2026 Haxe Foundation
33 *
44 * Permission is hereby granted, free of charge, to any person obtaining a
55 * copy of this software and associated documentation files (the "Software"),
2323package js .node .domain ;
2424
2525import haxe .Constraints .Function ;
26- import js . node . Timers . Timeout ;
26+ import haxe . extern . Rest ;
2727import js .node .events .EventEmitter ;
2828
2929/**
3030 Enumeration of events emitted by `Domain` objects.
31+
32+ Stability: 0 - Deprecated. Prefer `AsyncLocalStorage` / `async_hooks`.
33+
34+ Note: the former `'dispose'` event was removed with `Domain.dispose()` (DEP0012, End-of-Life in Node.js v9.0.0).
3135**/
3236@:deprecated (" The domain module is deprecated. Use AsyncLocalStorage / async_hooks instead." )
3337enum abstract DomainEvent <T : Function >(Event <T >) to Event <T > {
38+ /**
39+ Emitted when an error is routed to this domain.
40+ **/
3441 var Error : DomainEvent <DomainError -> Void > = " error" ;
35- var Dispose : DomainEvent <Void -> Void > = " dispose" ;
3642}
3743
3844/**
39- Any time an Error object is routed through a domain, a few extra fields are added to it.
45+ Extra fields added to an `Error` when it is routed through a domain.
46+
47+ These properties are set on the error object itself (typically a `js.lib.Error`).
4048**/
4149@:deprecated (" The domain module is deprecated. Use AsyncLocalStorage / async_hooks instead." )
4250typedef DomainError = {
@@ -46,7 +54,7 @@ typedef DomainError = {
4654 var domain : Domain ;
4755
4856 /**
49- The event emitter that emitted an 'error' event with the error object.
57+ The event emitter that emitted an ` 'error'` event with the error object.
5058 **/
5159 var domainEmitter : IEventEmitter ;
5260
@@ -62,57 +70,74 @@ typedef DomainError = {
6270}
6371
6472/**
65- The Domain class encapsulates the functionality of routing errors
66- and uncaught exceptions to the active Domain object.
73+ The `Domain` class encapsulates the functionality of routing errors
74+ and uncaught exceptions to the active `Domain` object.
75+
76+ Listen to its `'error'` event to handle caught errors.
77+
78+ Stability: 0 - Deprecated. Prefer `AsyncLocalStorage` / `async_hooks`.
79+
80+ @see https://nodejs.org/docs/latest-v24.x/api/domain.html#class-domain
6781**/
6882@:deprecated (" The domain module is deprecated. Use AsyncLocalStorage / async_hooks instead." )
6983extern class Domain extends EventEmitter <Domain > {
7084 /**
7185 Run the supplied function in the context of the domain, implicitly binding all event emitters, timers,
72- and lowlevel requests that are created in that context.
86+ and low-level requests that are created in that context.
87+
88+ Optionally, arguments can be passed to the function.
7389
7490 This is the most basic way to use a domain.
91+
92+ @see https://nodejs.org/docs/latest-v24.x/api/domain.html#domainrunfn-args
7593 **/
76- function run (fn : Void -> Void ) : Void ;
94+ function run (fn : Function , args : Rest < Dynamic >) : Dynamic ;
7795
7896 /**
79- An array of timers and event emitters that have been explicitly added to the domain.
97+ An array of event emitters that have been explicitly added to the domain.
98+
99+ @see https://nodejs.org/docs/latest-v24.x/api/domain.html#domainmembers
80100 **/
81- var members (default , null ): Array <haxe.extern. EitherType < IEventEmitter , Timeout > >;
101+ var members (default , null ): Array <IEventEmitter >;
82102
83103 /**
84104 Explicitly adds an `emitter` to the domain.
85105
86- If any event handlers called by the emitter throw an error, or if the emitter emits an error event,
87- it will be routed to the domain's error event, just like with implicit binding.
88-
89- This also works with timers that are returned from `setInterval` and `setTimeout`.
90- If their callback function throws, it will be caught by the domain 'error' handler.
106+ If any event handlers called by the emitter throw an error, or if the emitter emits an `'error'` event,
107+ it will be routed to the domain's `'error'` event, just like with implicit binding.
91108
92- If the Timer or EventEmitter was already bound to a domain, it is removed from that one,
109+ If the ` EventEmitter` was already bound to a domain, it is removed from that one,
93110 and bound to this one instead.
111+
112+ As of Node.js 9.3.0, this method no longer accepts timer objects.
113+
114+ @see https://nodejs.org/docs/latest-v24.x/api/domain.html#domainaddemitter
94115 **/
95- @:overload (function (emitter : Timeout ): Void {})
96116 function add (emitter : IEventEmitter ): Void ;
97117
98118 /**
99119 The opposite of `add`. Removes domain handling from the specified emitter.
120+
121+ @see https://nodejs.org/docs/latest-v24.x/api/domain.html#domainremoveemitter
100122 **/
101- @:overload (function (emitter : Timeout ): Void {})
102123 function remove (emitter : IEventEmitter ): Void ;
103124
104125 /**
105126 The returned function will be a wrapper around the supplied `callback` function.
106- When the returned function is called, any errors that are thrown will be routed to the domain's error event.
127+ When the returned function is called, any errors that are thrown will be routed to the domain's `'error'` event.
128+
129+ @see https://nodejs.org/docs/latest-v24.x/api/domain.html#domainbindcallback
107130 **/
108131 function bind <T : Function >(callback : T ): T ;
109132
110133 /**
111134 This method is almost identical to `bind`. However, in addition to catching thrown errors, it will also
112135 intercept `Error` objects sent as the first argument to the function.
113136
114- In this way, the common if (er != null) return callback(er); pattern
137+ In this way, the common ` if (err != null) return callback(err);` pattern
115138 can be replaced with a single error handler in a single place.
139+
140+ @see https://nodejs.org/docs/latest-v24.x/api/domain.html#domaininterceptcallback
116141 **/
117142 function intercept <T : Function >(callback : T ): T ;
118143
@@ -125,9 +150,9 @@ extern class Domain extends EventEmitter<Domain> {
125150 The call to `enter` delimits the beginning of a chain of asynchronous calls and I/O operations bound to a domain.
126151
127152 Calling `enter` changes only the active domain, and does not alter the domain itself.
128- Enter and exit can be called an arbitrary number of times on a single domain.
153+ `enter` and ` exit` can be called an arbitrary number of times on a single domain.
129154
130- If the domain on which `enter` is called has been disposed, `enter` will return without setting the domain.
155+ @see https://nodejs.org/docs/latest-v24.x/api/ domain.html#domainenter
131156 **/
132157 function enter (): Void ;
133158
@@ -142,29 +167,9 @@ extern class Domain extends EventEmitter<Domain> {
142167 `exit` will exit any domains nested within this domain.
143168
144169 Calling `exit` changes only the active domain, and does not alter the domain itself.
145- Enter and exit can be called an arbitrary number of times on a single domain.
170+ `enter` and ` exit` can be called an arbitrary number of times on a single domain.
146171
147- If the domain on which `exit` is called has been disposed, `exit` will return without exiting the domain.
172+ @see https://nodejs.org/docs/latest-v24.x/api/ domain.html#domainexit
148173 **/
149174 function exit (): Void ;
150-
151- /**
152- The `dispose` method destroys a domain, and makes a best effort attempt
153- to clean up any and all IO that is associated with the domain.
154-
155- Streams are aborted, ended, closed, and/or destroyed. Timers are cleared.
156- Explicitly bound callbacks are no longer called.
157-
158- Any error events that are raised as a result of this are ignored.
159-
160- The intention of calling `dispose` is generally to prevent cascading errors when a critical part of
161- the Domain context is found to be in an error state.
162-
163- Once the domain is disposed the 'dispose' event will emit.
164-
165- Note that IO might still be performed. However, to the highest degree possible, once a domain is disposed,
166- further errors from the emitters in that set will be ignored. So, even if some remaining actions are still
167- in flight, Node.js will not communicate further about them.
168- **/
169- function dispose (): Void ;
170175}
0 commit comments