Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Use modern exponentiation operator (**) instead of Math.pow()
- Replace string concatenation with modern template literals
- Remove redundant 'use strict' directives as modules are automatically in strict mode
- Refactor assignment-in-expression patterns to improve code clarity and readability

## v0.10.9
- Add support for IPv6 urls
Expand Down
1 change: 0 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
},
"suspicious": {
"noRedundantUseStrict": "error",
"noAssignInExpressions": "off",
"noAsyncPromiseExecutor": "off",
"noDoubleEquals": "off",
"noGlobalIsNan": "off",
Expand Down
16 changes: 10 additions & 6 deletions lib/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ class Channel extends EventEmitter {
}),
);
this.on('close', function () {
let cb;
while ((cb = this.unconfirmed.shift())) {
let cb = this.unconfirmed.shift();
while (cb) {
if (cb) cb(new Error('channel closed'));
cb = this.unconfirmed.shift();
}
});
// message frame state machine
Expand Down Expand Up @@ -162,14 +163,17 @@ class Channel extends EventEmitter {
}

_rejectPending() {
function rej(r) {
function reject(r) {
r(new Error('Channel ended, no reply will be forthcoming'));
}
if (this.reply !== null) rej(this.reply);
if (this.reply !== null) reject(this.reply);
this.reply = null;

let discard;
while ((discard = this.pending.shift())) rej(discard.reply);
let discard = this.pending.shift();
while (discard) {
if (discard) reject(discard.reply);
discard = this.pending.shift();
}
this.pending = null; // so pushes will break
}

Expand Down
5 changes: 3 additions & 2 deletions lib/channel_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,10 @@ class ConfirmChannel extends Channel {
});
// Channel closed
if (!this.pending) {
let cb;
while ((cb = this.unconfirmed.shift())) {
let cb = this.unconfirmed.shift();
while (cb) {
if (cb) cb(new Error('channel closed'));
cb = this.unconfirmed.shift();
}
}
return Promise.all(awaiting);
Expand Down
11 changes: 7 additions & 4 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class Connection extends EventEmitter {
constructor(underlying) {
super();

const stream = (this.stream = wrapStream(underlying));
this.muxer = new Mux(stream);
this.stream = wrapStream(underlying);
this.muxer = new Mux(this.stream);

// frames
this.rest = Buffer.alloc(0);
Expand Down Expand Up @@ -406,8 +406,11 @@ class Connection extends EventEmitter {

function go() {
try {
let f;
while ((f = self.recvFrame())) self.accept(f);
let frame = self.recvFrame();
while (frame) {
self.accept(frame);
frame = self.recvFrame();
}
} catch (e) {
self.emit('frameError', e);
}
Expand Down
9 changes: 5 additions & 4 deletions lib/mux.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ class Mux {
// Try to read a chunk from each stream in turn, until all streams
// are empty, or we exhaust our ability to accept chunks.
function roundrobin(streams) {
let s;
while (accepting && (s = streams.shift())) {
const chunk = s.read();
let stream = streams.shift();
while (accepting && stream) {
const chunk = stream.read();
if (chunk !== null) {
accepting = out.write(chunk);
streams.push(s);
streams.push(stream);
}
stream = streams.shift();
}
}

Expand Down
13 changes: 7 additions & 6 deletions test/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,16 @@ suite('Content framing', function () {
const frames = new Frames(input);
frames.frameMax = max;
frames.sendMessage(0, defs.BasicDeliver, content.method, defs.BasicProperties, content.header, content.body);
let f,
_i = 0,
largest = 0;
while ((f = input.read())) {
let _i = 0;
let largest = 0;
let frame = input.read();
while (frame) {
_i++;
if (f.length > largest) largest = f.length;
if (f.length > max) {
if (frame.length > largest) largest = frame.length;
if (frame.length > max) {
return false;
}
frame = input.read();
}
// The ratio of frames to 'contents' should always be >= 2
// (one properties frame and at least one content frame); > 2
Expand Down
4 changes: 3 additions & 1 deletion test/mux.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ test('unpipe', function (done) {
schedule(function () {
// exhaust so that 'end' fires
let v;
while ((v = input.read()));
do {
v = input.read();
} while (v);
});
});
});
Expand Down