Skip to content

Commit

Permalink
[FIX] change transport.send() to not return a promise (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart authored May 26, 2022
1 parent c335a62 commit bae23ac
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
8 changes: 3 additions & 5 deletions nats-base-client/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ export class ProtocolHandler implements Dispatcher<ParserEvent> {
}

processPing() {
this.transport.send(PONG_CMD).catch(() => {/*ignoring socket error*/});
this.transport.send(PONG_CMD);
}

processPong() {
Expand Down Expand Up @@ -693,9 +693,7 @@ export class ProtocolHandler implements Dispatcher<ParserEvent> {
}
});
if (cmds.length) {
this.transport.send(encode(cmds.join(""))).catch(
() => {/*ignoring socket error*/},
);
this.transport.send(encode(cmds.join("")));
}
}

Expand Down Expand Up @@ -750,7 +748,7 @@ export class ProtocolHandler implements Dispatcher<ParserEvent> {

if (this.outbound.size()) {
const d = this.outbound.drain();
this.transport.send(d).catch(() => {/*ignoring socket error*/});
this.transport.send(d);
}
}

Expand Down
2 changes: 2 additions & 0 deletions nats-base-client/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class RequestMany extends BaseRequest implements Request {
this.done.then(() => {
this.callback(null, null);
});
// @ts-ignore: node is not a number
this.timer = setTimeout(() => {
this.cancel();
}, opts.maxWait);
Expand Down Expand Up @@ -110,6 +111,7 @@ export class RequestMany extends BaseRequest implements Request {

if (this.opts.strategy === RequestStrategy.JitterTimer) {
clearTimeout(this.timer);
// @ts-ignore: node is not a number
this.timer = setTimeout(() => {
this.cancel();
}, 300);
Expand Down
2 changes: 1 addition & 1 deletion nats-base-client/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export interface Transport extends AsyncIterable<Uint8Array> {

isEncrypted(): boolean;

send(frame: Uint8Array): Promise<void>;
send(frame: Uint8Array): void;

close(err?: Error): Promise<void>;

Expand Down
14 changes: 10 additions & 4 deletions src/deno_transport.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 The NATS Authors
* Copyright 2020-2022 The NATS Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -33,7 +33,7 @@ import {
} from "../nats-base-client/internal_mod.ts";
import type { TlsOptions } from "../nats-base-client/types.ts";

const VERSION = "1.7.0";
const VERSION = "1.7.1";
const LANG = "nats.deno";

// if trying to simply write to the connection for some reason
Expand Down Expand Up @@ -223,8 +223,13 @@ export class DenoTransport implements Transport {
});
}

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

isEncrypted(): boolean {
Expand All @@ -247,6 +252,7 @@ export class DenoTransport implements Transport {
try {
// this is a noop but gives us a place to hang
// a close and ensure that we sent all before closing
// we wait for the operation to fail or succeed
await this.enqueue(TE.encode(""));
} catch (err) {
if (this.options.debug) {
Expand Down

0 comments on commit bae23ac

Please sign in to comment.