fluentd-node
Advanced tools
Comparing version 0.0.10 to 0.0.11
@@ -166,2 +166,8 @@ import EventTime from "./event_time"; | ||
disconnect?: Partial<DisconnectOptions>; | ||
/** | ||
* Disable connection on client creation. Expects the client to call .connect to start sending messages. | ||
* | ||
* Defaults to false | ||
*/ | ||
disableAutoconnect?: boolean; | ||
}; | ||
@@ -260,3 +266,3 @@ /** | ||
/** | ||
* Connects the client. Happens automatically during construction, but can be called after a `disconnect()` to resume the client. | ||
* Connects the client. Can happen automatically during construction, but can be called after a `disconnect()` to resume the client. | ||
*/ | ||
@@ -263,0 +269,0 @@ connect(): Promise<void>; |
@@ -90,6 +90,9 @@ "use strict"; | ||
} | ||
// Only connect if we're able to reconnect | ||
// Only connect if we're able to reconnect and user has not disabled auto connect | ||
// Otherwise we expect an explicit connect() which will handle connection errors | ||
if (!((_a = options.socket) === null || _a === void 0 ? void 0 : _a.disableReconnect)) { | ||
this.connect(); | ||
const autoConnect = !((_a = options.socket) === null || _a === void 0 ? void 0 : _a.disableReconnect) && !options.disableAutoconnect; | ||
if (autoConnect) { | ||
// Catch errors and noop them, so the constructor doesn't throw unhandled promises | ||
// They can be handled by the socket "error" event handler anyway | ||
this.connect().catch(() => { }); | ||
} | ||
@@ -203,3 +206,3 @@ } | ||
/** | ||
* Connects the client. Happens automatically during construction, but can be called after a `disconnect()` to resume the client. | ||
* Connects the client. Can happen automatically during construction, but can be called after a `disconnect()` to resume the client. | ||
*/ | ||
@@ -206,0 +209,0 @@ async connect() { |
@@ -124,2 +124,4 @@ /// <reference types="node" /> | ||
* | ||
* Can throw a connection error, we may reconnect from this state, but the error will still be thrown | ||
* | ||
* @returns void | ||
@@ -126,0 +128,0 @@ */ |
@@ -157,2 +157,4 @@ "use strict"; | ||
* | ||
* Can throw a connection error, we may reconnect from this state, but the error will still be thrown | ||
* | ||
* @returns void | ||
@@ -182,14 +184,3 @@ */ | ||
} | ||
try { | ||
await this.openSocket(); | ||
} | ||
catch (e) { | ||
if (!this.reconnectEnabled) { | ||
throw e; | ||
} | ||
else { | ||
// Suppress connection errors if reconnections are enabled | ||
return; | ||
} | ||
} | ||
await this.openSocket(); | ||
} | ||
@@ -196,0 +187,0 @@ else if (!this.socket.writable) { |
{ | ||
"name": "fluentd-node", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "A fluent protocol implementation in node", | ||
@@ -5,0 +5,0 @@ "main": "./build/src/index.js", |
@@ -198,2 +198,8 @@ import { | ||
disconnect?: Partial<DisconnectOptions>; | ||
/** | ||
* Disable connection on client creation. Expects the client to call .connect to start sending messages. | ||
* | ||
* Defaults to false | ||
*/ | ||
disableAutoconnect?: boolean; | ||
}; | ||
@@ -300,6 +306,10 @@ | ||
// Only connect if we're able to reconnect | ||
// Only connect if we're able to reconnect and user has not disabled auto connect | ||
// Otherwise we expect an explicit connect() which will handle connection errors | ||
if (!options.socket?.disableReconnect) { | ||
this.connect(); | ||
const autoConnect = | ||
!options.socket?.disableReconnect && !options.disableAutoconnect; | ||
if (autoConnect) { | ||
// Catch errors and noop them, so the constructor doesn't throw unhandled promises | ||
// They can be handled by the socket "error" event handler anyway | ||
this.connect().catch(() => {}); | ||
} | ||
@@ -473,3 +483,3 @@ } | ||
/** | ||
* Connects the client. Happens automatically during construction, but can be called after a `disconnect()` to resume the client. | ||
* Connects the client. Can happen automatically during construction, but can be called after a `disconnect()` to resume the client. | ||
*/ | ||
@@ -476,0 +486,0 @@ public async connect(): Promise<void> { |
@@ -254,2 +254,4 @@ import * as net from "net"; | ||
* | ||
* Can throw a connection error, we may reconnect from this state, but the error will still be thrown | ||
* | ||
* @returns void | ||
@@ -283,12 +285,3 @@ */ | ||
} | ||
try { | ||
await this.openSocket(); | ||
} catch (e) { | ||
if (!this.reconnectEnabled) { | ||
throw e; | ||
} else { | ||
// Suppress connection errors if reconnections are enabled | ||
return; | ||
} | ||
} | ||
await this.openSocket(); | ||
} else if (!this.socket.writable) { | ||
@@ -295,0 +288,0 @@ await this.disconnect(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
306365
7160