Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
static/legacy/
external/
build/
# Top level await isn't supported till ESLint 8
locale/en/blog/release/v17.0.0.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we blocked because standard is still using eslint 7.x?

I think I've expressed my opinion in the past, standard does not catch many of real issues and personally I never use it. prettier doesn't catch real issues either.

Just thinking out loud for the future :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I believe the ESLint upgrade is blocked on prettier, but eslint-plugin-promise just released a compatible version, so that might have been the last one remaining

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, as long as someone remembers to revert this later :)

35 changes: 34 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,38 @@
],
"rules": {
"prettier/prettier": "error"
}
},
"overrides": [
{
"files": [
"**/*.md"
],
"plugins": [
"markdown"
],
"processor": "markdown/markdown"
},
{
"files": [
"**/*.md/*.js"
],
"rules": {
"eqeqeq": "off",
"no-const-assign": "off",
"no-undef": "off",
"no-unused-expressions": "off",
"no-unused-vars": "off",
"node/handle-callback-err": "off",
"node/no-deprecated-api": "off",
"prefer-const": "off",
"prettier/prettier": [
"error",
{
"singleQuote": true,
"trailingComma": "none"
}
]
}
}
]
}
2 changes: 0 additions & 2 deletions locale/en/blog/release/v12.16.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ The new `EventEmitter.on` static method allows to async iterate over events:
const { on, EventEmitter } = require('events');

(async () => {

const ee = new EventEmitter();

// Emit later on
Expand All @@ -145,7 +144,6 @@ const { on, EventEmitter } = require('events');
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}

})();
```

Expand Down
20 changes: 11 additions & 9 deletions locale/en/blog/release/v12.17.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,18 @@ function logWithId(msg) {
}

let idSeq = 0;
http.createServer((req, res) => {
asyncLocalStorage.run(idSeq++, () => {
logWithId('start');
// Imagine any chain of async operations here.
setImmediate(() => {
logWithId('finish');
res.end();
http
.createServer((req, res) => {
asyncLocalStorage.run(idSeq++, () => {
logWithId('start');
// Imagine any chain of async operations here.
setImmediate(() => {
logWithId('finish');
res.end();
});
});
});
}).listen(8080);
})
.listen(8080);
```

In this example, the `logWithId` function will always know what the current
Expand Down
2 changes: 1 addition & 1 deletion locale/en/blog/release/v14.17.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ MySQL.prototype.query = function query(queryString, values, callback) {
// Broadcast query information whenever a query is made
channel.publish({
query: queryString,
host: this.hostname,
host: this.hostname
});

this.doQuery(queryString, values, callback);
Expand Down
2 changes: 1 addition & 1 deletion locale/en/blog/release/v15.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ MySQL.prototype.query = function query(queryString, values, callback) {
// Broadcast query information whenever a query is made
channel.publish({
query: queryString,
host: this.hostname,
host: this.hostname
});

this.doQuery(queryString, values, callback);
Expand Down
14 changes: 10 additions & 4 deletions locale/en/blog/release/v8.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,12 @@ const util = require('util');
const readfile = util.promisify(fs.readFile);

readfile('/some/file')
.then((data) => { /** ... **/ })
.catch((err) => { /** ... **/ });
.then((data) => {
/** ... **/
})
.catch((err) => {
/** ... **/
});
```

### Console changes
Expand Down Expand Up @@ -183,7 +187,7 @@ Codes are manifest to the user in two ways:
For instance, calling `assert(false)` will generate the following
`AssertionError`:

```js
```shell
> assert(false)
AssertionError [ERR_ASSERTION]: false == true
at repl:1:1
Expand Down Expand Up @@ -240,7 +244,9 @@ const session = new inspector.Session();
session.connect();

// Listen for inspector events
session.on('inspectorNotification', (message) => { /** ... **/ });
session.on('inspectorNotification', (message) => {
/** ... **/
});

// Send messages to the inspector
session.post(message);
Expand Down
2 changes: 1 addition & 1 deletion locale/en/docs/guides/buffer-constructor-deprecation.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ compiles to.
For Node.js 0.10.x (and below) support:

```js
var buf;
let buf;
if (Buffer.alloc) {
buf = Buffer.alloc(number);
} else {
Expand Down
165 changes: 96 additions & 69 deletions locale/en/docs/guides/domain-postmortem.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const c = require('./c');

// module b.js
const d = require('domain').create();
d.on('error', () => { /* silence everything */ });
d.on('error', () => {
/* silence everything */
});
d.enter();

// module c.js
Expand Down Expand Up @@ -57,10 +59,14 @@ const net = require('net');
const d = domain.create();
d.on('error', (err) => console.error(err.message));

d.run(() => net.createServer((c) => {
c.end();
c.write('bye');
}).listen(8000));
d.run(() =>
net
.createServer((c) => {
c.end();
c.write('bye');
})
.listen(8000)
);
```

Even manually removing the connection via `d.remove(c)` does not prevent the
Expand All @@ -77,17 +83,19 @@ const d = domain.create();
d.on('error', () => console.error('d intercepted an error'));

d.run(() => {
const server = net.createServer((c) => {
const e = domain.create(); // No 'error' handler being set.
e.run(() => {
// This will not be caught by d's error handler.
setImmediate(() => {
throw new Error('thrown from setImmediate');
const server = net
.createServer((c) => {
const e = domain.create(); // No 'error' handler being set.
e.run(() => {
// This will not be caught by d's error handler.
setImmediate(() => {
throw new Error('thrown from setImmediate');
});
// Though this one will bubble to d's error handler.
throw new Error('immediately thrown');
});
// Though this one will bubble to d's error handler.
throw new Error('immediately thrown');
});
}).listen(8080);
})
.listen(8080);
});
```

Expand Down Expand Up @@ -118,21 +126,25 @@ example of the failing of error propagation:
```js
const d1 = domain.create();
d1.foo = true; // custom member to make more visible in console
d1.on('error', (er) => { /* handle error */ });
d1.on('error', (er) => {
/* handle error */
});

d1.run(() => setTimeout(() => {
const d2 = domain.create();
d2.bar = 43;
d2.on('error', (er) => console.error(er.message, domain._stack));
d2.run(() => {
setTimeout(() => {
d1.run(() =>
setTimeout(() => {
const d2 = domain.create();
d2.bar = 43;
d2.on('error', (er) => console.error(er.message, domain._stack));
d2.run(() => {
setTimeout(() => {
throw new Error('outer');
setTimeout(() => {
throw new Error('outer');
});
throw new Error('inner');
});
throw new Error('inner');
});
});
}));
})
);
```

Even in the case that the domain instances are being used for local storage so
Expand Down Expand Up @@ -176,16 +188,15 @@ let uid = 0;

// Setting up temporary resources
const buf = Buffer.alloc(FILESIZE);
for (let i = 0; i < buf.length; i++)
buf[i] = ((Math.random() * 1e3) % 78) + 48; // Basic ASCII
for (let i = 0; i < buf.length; i++) buf[i] = ((Math.random() * 1e3) % 78) + 48; // Basic ASCII
fs.writeFileSync(FILENAME, buf);

function ConnectionResource(c) {
EE.call(this);
this._connection = c;
this._alive = true;
this._domain = domain.create();
this._id = Math.random().toString(32).substr(2).substr(0, 8) + (++uid);
this._id = Math.random().toString(32).substr(2).substr(0, 8) + ++uid;

this._domain.add(c);
this._domain.on('error', () => {
Expand Down Expand Up @@ -214,18 +225,24 @@ ConnectionResource.prototype.write = function write(chunk) {
};

// Example begin
net.createServer((c) => {
const cr = new ConnectionResource(c);
net
.createServer((c) => {
const cr = new ConnectionResource(c);

const d1 = domain.create();
fs.open(FILENAME, 'r', d1.intercept((fd) => {
streamInParts(fd, cr, 0);
}));
const d1 = domain.create();
fs.open(
FILENAME,
'r',
d1.intercept((fd) => {
streamInParts(fd, cr, 0);
})
);

pipeData(cr);
pipeData(cr);

c.on('close', () => cr.end());
}).listen(8080);
c.on('close', () => cr.end());
})
.listen(8080);

function streamInParts(fd, cr, pos) {
const d2 = domain.create();
Expand All @@ -234,24 +251,33 @@ function streamInParts(fd, cr, pos) {
print('d2 error:', er.message);
cr.end();
});
fs.read(fd, Buffer.alloc(10), 0, 10, pos, d2.intercept((bRead, buf) => {
if (!cr.isAlive()) {
return fs.close(fd);
}
if (cr._connection.bytesWritten < FILESIZE) {
// Documentation says callback is optional, but doesn't mention that if
// the write fails an exception will be thrown.
const goodtogo = cr.write(buf);
if (goodtogo) {
setTimeout(() => streamInParts(fd, cr, pos + bRead), 1000);
} else {
cr._connection.once('drain', () => streamInParts(fd, cr, pos + bRead));
fs.read(
fd,
Buffer.alloc(10),
0,
10,
pos,
d2.intercept((bRead, buf) => {
if (!cr.isAlive()) {
return fs.close(fd);
}
return;
}
cr.end(buf);
fs.close(fd);
}));
if (cr._connection.bytesWritten < FILESIZE) {
// Documentation says callback is optional, but doesn't mention that if
// the write fails an exception will be thrown.
const goodtogo = cr.write(buf);
if (goodtogo) {
setTimeout(() => streamInParts(fd, cr, pos + bRead), 1000);
} else {
cr._connection.once('drain', () =>
streamInParts(fd, cr, pos + bRead)
);
}
return;
}
cr.end(buf);
fs.close(fd);
})
);
}

function pipeData(cr) {
Expand Down Expand Up @@ -293,9 +319,8 @@ process.on('exit', () => {
fs.unlinkSync(pipeList[i]);
}
fs.unlinkSync(FILENAME);
} catch (e) { }
} catch (e) {}
});

```

* When a new connection happens, concurrently:
Expand Down Expand Up @@ -344,18 +369,20 @@ propagate data along asynchronous stacks:
const domain = require('domain');
const net = require('net');

const server = net.createServer((c) => {
// Use a domain to propagate data across events within the
// connection so that we don't have to pass arguments
// everywhere.
const d = domain.create();
d.data = { connection: c };
d.add(c);
// Mock class that does some useless async data transformation
// for demonstration purposes.
const ds = new DataStream(dataTransformed);
c.on('data', (chunk) => ds.data(chunk));
}).listen(8080, () => console.log('listening on 8080'));
const server = net
.createServer((c) => {
// Use a domain to propagate data across events within the
// connection so that we don't have to pass arguments
// everywhere.
const d = domain.create();
d.data = { connection: c };
d.add(c);
// Mock class that does some useless async data transformation
// for demonstration purposes.
const ds = new DataStream(dataTransformed);
c.on('data', (chunk) => ds.data(chunk));
})
.listen(8080, () => console.log('listening on 8080'));

function dataTransformed(chunk) {
// FAIL! Because the DataStream instance also created a
Expand Down
Loading