From f6def612af3819a95743e9d95696de9c4d3729ee Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Wed, 1 Feb 2017 23:14:40 +0200 Subject: [PATCH 1/4] doc: var -> const in domain.md --- doc/api/domain.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/api/domain.md b/doc/api/domain.md index cfea9ddeff81f8..030b7c75c7f14e 100644 --- a/doc/api/domain.md +++ b/doc/api/domain.md @@ -47,7 +47,7 @@ For example, this is not a good idea: ```js // XXX WARNING! BAD IDEA! -var d = require('domain').create(); +const d = require('domain').create(); d.on('error', (er) => { // The error won't crash the process, but what it does is worse! // Though we've prevented abrupt process restarting, we are leaking @@ -104,7 +104,7 @@ if (cluster.isMaster) { // worker processes to serve requests. How it works, caveats, etc. const server = require('http').createServer((req, res) => { - var d = domain.create(); + const d = domain.create(); d.on('error', (er) => { console.error('error', er.stack); @@ -115,7 +115,7 @@ if (cluster.isMaster) { try { // make sure we close down within 30 seconds - var killtimer = setTimeout(() => { + const killtimer = setTimeout(() => { process.exit(1); }, 30000); // But don't keep the process open just for that! @@ -239,7 +239,7 @@ serverDomain.run(() => { // req and res are also created in the scope of serverDomain // however, we'd prefer to have a separate domain for each request. // create it first thing, and add req and res to it. - var reqd = domain.create(); + const reqd = domain.create(); reqd.add(req); reqd.add(res); reqd.on('error', (er) => { From fe0e06116f38e9d8b1b7a45798f19999b520417d Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Wed, 1 Feb 2017 23:17:27 +0200 Subject: [PATCH 2/4] doc: concatenations -> templates in domain.md --- doc/api/domain.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/api/domain.md b/doc/api/domain.md index 030b7c75c7f14e..fad06db50e807a 100644 --- a/doc/api/domain.md +++ b/doc/api/domain.md @@ -53,7 +53,7 @@ d.on('error', (er) => { // Though we've prevented abrupt process restarting, we are leaking // resources like crazy if this ever happens. // This is no better than process.on('uncaughtException')! - console.log('error, but oh well', er.message); + console.log(`error, but oh well ${er.message}`); }); d.run(() => { require('http').createServer((req, res) => { @@ -106,7 +106,7 @@ if (cluster.isMaster) { const server = require('http').createServer((req, res) => { const d = domain.create(); d.on('error', (er) => { - console.error('error', er.stack); + console.error(`error ${er.stack}`); // Note: we're in dangerous territory! // By definition, something unexpected occurred, @@ -135,7 +135,7 @@ if (cluster.isMaster) { res.end('Oops, there was a problem!\n'); } catch (er2) { // oh well, not much we can do at this point. - console.error('Error sending 500!', er2.stack); + console.error(`Error sending 500! ${er2.stack}`); } }); From 41173ecfc6d3447b85cfd133cda89d160b9f6c52 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Wed, 1 Feb 2017 23:18:27 +0200 Subject: [PATCH 3/4] doc: add missing space in domain.md --- doc/api/domain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/domain.md b/doc/api/domain.md index fad06db50e807a..dba64b67e9fb9d 100644 --- a/doc/api/domain.md +++ b/doc/api/domain.md @@ -156,7 +156,7 @@ if (cluster.isMaster) { // This part is not important. Just an example routing thing. // You'd put your fancy application logic here. function handleRequest(req, res) { - switch(req.url) { + switch (req.url) { case '/error': // We do some async stuff, and then... setTimeout(() => { From bfef75b76ec2da2b5eb44dc9a5ee8c224258b55a Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Thu, 2 Feb 2017 01:43:03 +0200 Subject: [PATCH 4/4] doc: fix variable shadowing in domain.md Fixed basing on the previous example. --- doc/api/domain.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/domain.md b/doc/api/domain.md index dba64b67e9fb9d..1cc25e0cf8d8fb 100644 --- a/doc/api/domain.md +++ b/doc/api/domain.md @@ -247,8 +247,8 @@ serverDomain.run(() => { try { res.writeHead(500); res.end('Error occurred, sorry.'); - } catch (er) { - console.error('Error sending 500', er, req.url); + } catch (er2) { + console.error('Error sending 500', er2, req.url); } }); }).listen(1337);