Skip to content

Commit 6a45265

Browse files
vsemozhetbytitaloacasas
authored andcommitted
doc: update code examples in domain.md
* var -> const * string concatenation -> template strings PR-URL: #11110 Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 8a5c0fb commit 6a45265

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

doc/api/domain.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ For example, this is not a good idea:
4747
```js
4848
// XXX WARNING! BAD IDEA!
4949

50-
var d = require('domain').create();
50+
const d = require('domain').create();
5151
d.on('error', (er) => {
5252
// The error won't crash the process, but what it does is worse!
5353
// Though we've prevented abrupt process restarting, we are leaking
5454
// resources like crazy if this ever happens.
5555
// This is no better than process.on('uncaughtException')!
56-
console.log('error, but oh well', er.message);
56+
console.log(`error, but oh well ${er.message}`);
5757
});
5858
d.run(() => {
5959
require('http').createServer((req, res) => {
@@ -104,9 +104,9 @@ if (cluster.isMaster) {
104104
// worker processes to serve requests. How it works, caveats, etc.
105105

106106
const server = require('http').createServer((req, res) => {
107-
var d = domain.create();
107+
const d = domain.create();
108108
d.on('error', (er) => {
109-
console.error('error', er.stack);
109+
console.error(`error ${er.stack}`);
110110

111111
// Note: we're in dangerous territory!
112112
// By definition, something unexpected occurred,
@@ -115,7 +115,7 @@ if (cluster.isMaster) {
115115

116116
try {
117117
// make sure we close down within 30 seconds
118-
var killtimer = setTimeout(() => {
118+
const killtimer = setTimeout(() => {
119119
process.exit(1);
120120
}, 30000);
121121
// But don't keep the process open just for that!
@@ -135,7 +135,7 @@ if (cluster.isMaster) {
135135
res.end('Oops, there was a problem!\n');
136136
} catch (er2) {
137137
// oh well, not much we can do at this point.
138-
console.error('Error sending 500!', er2.stack);
138+
console.error(`Error sending 500! ${er2.stack}`);
139139
}
140140
});
141141

@@ -156,7 +156,7 @@ if (cluster.isMaster) {
156156
// This part is not important. Just an example routing thing.
157157
// You'd put your fancy application logic here.
158158
function handleRequest(req, res) {
159-
switch(req.url) {
159+
switch (req.url) {
160160
case '/error':
161161
// We do some async stuff, and then...
162162
setTimeout(() => {
@@ -239,16 +239,16 @@ serverDomain.run(() => {
239239
// req and res are also created in the scope of serverDomain
240240
// however, we'd prefer to have a separate domain for each request.
241241
// create it first thing, and add req and res to it.
242-
var reqd = domain.create();
242+
const reqd = domain.create();
243243
reqd.add(req);
244244
reqd.add(res);
245245
reqd.on('error', (er) => {
246246
console.error('Error', er, req.url);
247247
try {
248248
res.writeHead(500);
249249
res.end('Error occurred, sorry.');
250-
} catch (er) {
251-
console.error('Error sending 500', er, req.url);
250+
} catch (er2) {
251+
console.error('Error sending 500', er2, req.url);
252252
}
253253
});
254254
}).listen(1337);

0 commit comments

Comments
 (0)