ferrum-db-client
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -7,3 +7,3 @@ "use strict"; | ||
const utils_1 = require("./utils"); | ||
const MAX_BUFFER_SIZE = 128 * 1024 * 1024; | ||
const MAX_BUFFER_SIZE = 512 * 1024 * 1024; | ||
class FerrumServerClient { | ||
@@ -52,3 +52,3 @@ constructor(socket) { | ||
const toRead = Math.min(data.length - readOffset, msgRemaining); | ||
if (toRead + writeOffset > msgBuffer.length) { | ||
while (toRead + writeOffset > msgBuffer.length) { | ||
msgBuffer = this.expandBuffer(msgBuffer, MAX_BUFFER_SIZE); | ||
@@ -88,3 +88,2 @@ } | ||
} | ||
this.socket.connect(this.port, this.ip); | ||
for (const pendingId of this.pending.keys()) { | ||
@@ -97,2 +96,5 @@ const pending = this.pending.get(pendingId); | ||
} | ||
this.socket.connect(this.port, this.ip, () => { | ||
this.lastResponse = Date.now(); | ||
}); | ||
} | ||
@@ -106,4 +108,4 @@ disconnect() { | ||
async heartbeat() { | ||
if (Date.now() - this.lastResponse > 6000) { | ||
this.socket.destroy(); | ||
if (Date.now() - this.lastResponse > 12000) { | ||
this.socket.destroy(new Error('Heartbeat timeout')); | ||
return; | ||
@@ -160,4 +162,8 @@ } | ||
getResponse(myId) { | ||
return new Promise((resolve) => { | ||
return new Promise((resolve, reject) => { | ||
const timeout = setTimeout(() => { | ||
reject(new Error('Timeout waiting for database response')); | ||
}, 90000); | ||
this.pending.set(myId, (buffer) => { | ||
clearTimeout(timeout); | ||
resolve(buffer); | ||
@@ -164,0 +170,0 @@ }); |
{ | ||
"name": "ferrum-db-client", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "typings": "dist/index.d.ts", |
@@ -6,3 +6,3 @@ import { BinaryWriter, Encoding } from 'csharp-binary-stream'; | ||
const MAX_BUFFER_SIZE = 128 * 1024 * 1024; | ||
const MAX_BUFFER_SIZE = 512 * 1024 * 1024; | ||
@@ -63,3 +63,3 @@ export class FerrumServerClient { | ||
const toRead = Math.min(data.length - readOffset, msgRemaining); | ||
if (toRead + writeOffset > msgBuffer.length) { | ||
while (toRead + writeOffset > msgBuffer.length) { | ||
msgBuffer = this.expandBuffer(msgBuffer, MAX_BUFFER_SIZE); | ||
@@ -104,3 +104,2 @@ } | ||
this.socket.connect(this.port, this.ip); | ||
for (const pendingId of this.pending.keys()) { | ||
@@ -113,2 +112,5 @@ const pending = this.pending.get(pendingId); | ||
} | ||
this.socket.connect(this.port, this.ip, () => { | ||
this.lastResponse = Date.now(); | ||
}); | ||
} | ||
@@ -124,4 +126,4 @@ | ||
public async heartbeat(): Promise<void> { | ||
if (Date.now() - this.lastResponse > 6000) { | ||
this.socket.destroy(); | ||
if (Date.now() - this.lastResponse > 12000) { | ||
this.socket.destroy(new Error('Heartbeat timeout')); | ||
return; | ||
@@ -188,4 +190,9 @@ } | ||
public getResponse(myId: number): Promise<Buffer> { | ||
return new Promise((resolve) => { | ||
return new Promise((resolve, reject) => { | ||
const timeout = setTimeout(() => { | ||
reject(new Error('Timeout waiting for database response')); | ||
}, 90000); | ||
this.pending.set(myId, (buffer) => { | ||
clearTimeout(timeout); | ||
resolve(buffer); | ||
@@ -192,0 +199,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
255920
3033