Skip to content

Commit

Permalink
[UPDATE] nbc to v1.7.1 (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart authored May 26, 2022
1 parent 9bb4118 commit 4e81d8a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nats",
"version": "2.7.0",
"version": "2.7.1",
"description": "Node.js client for NATS, a lightweight, high-performance cloud native messaging system",
"keywords": [
"nats",
Expand Down Expand Up @@ -40,7 +40,7 @@
"build": "tsc",
"cjs": "deno run --allow-all bin/cjs-fix-imports.ts -o nats-base-client/ ./.deps/nats.deno/nats-base-client/",
"clean": "shx rm -Rf ./lib/* ./nats-base-client ./.deps",
"clone-nbc": "shx mkdir -p ./.deps && cd ./.deps && git clone --branch v1.7.0 https://github.com/nats-io/nats.deno.git",
"clone-nbc": "shx mkdir -p ./.deps && cd ./.deps && git clone --branch v1.7.1 https://github.com/nats-io/nats.deno.git",
"fmt": "deno fmt ./src/ ./examples/ ./test/",
"prepack": "npm run clone-nbc && npm run cjs && npm run check-package && npm run build",
"ava": "nyc ava --verbose -T 60000",
Expand Down
35 changes: 27 additions & 8 deletions src/node_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const { resolve } = require("path");
const { readFile, existsSync } = require("fs");
const dns = require("dns");

const VERSION = "2.7.0";
const VERSION = "2.7.1";
const LANG = "nats.js";

export class NodeTransport implements Transport {
Expand Down Expand Up @@ -319,23 +319,42 @@ export class NodeTransport implements Transport {
return this.socket instanceof TLSSocket;
}

send(frame: Uint8Array): Promise<void> {
_send(frame: Uint8Array): Promise<void> {
if (this.isClosed) {
return Promise.resolve();
}
if (this.options.debug) {
console.info(`< ${render(frame)}`);
}
const d = deferred<void>();
this.socket.write(frame, (err) => {
if (err) {
return d.reject(err);
try {
this.socket.write(frame, (err: Error | undefined) => {
if (err) {
if (this.options.debug) {
console.error(`!!! ${render(frame)}: ${err}`);
}
return d.reject(err);
}
return d.resolve();
});
} catch (err) {
if (this.options.debug) {
console.error(`!!! ${render(frame)}: ${err}`);
}
return d.resolve();
});
d.reject(err);
}
return d;
}

send(frame: Uint8Array): void {
const p = this._send(frame);
p.catch((_err) => {
// we ignore write errors because client will
// fail on a read or when the heartbeat timer
// detects a stale connection
});
}

private async _closed(err?: Error, internal = true): Promise<void> {
// if this connection didn't succeed, then ignore it.
if (!this.connected) return;
Expand All @@ -344,7 +363,7 @@ export class NodeTransport implements Transport {
try {
// this is a noop for the server, but gives us a place to hang
// a close and ensure that we sent all before closing
await this.send(new TextEncoder().encode("+OK\r\n"));
await this._send(new TextEncoder().encode("+OK\r\n"));
} catch (err) {
if (this.options.debug) {
console.log("transport close terminated with an error", err);
Expand Down
2 changes: 1 addition & 1 deletion test/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ test("basics - subscription timeout auto cancels", async (t) => {
c++;
}
})().catch((err) => {
t.fail(err);
t.fail(err.message);
});

nc.publish(subj);
Expand Down

0 comments on commit 4e81d8a

Please sign in to comment.