@push-rpc/core
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -34,3 +34,3 @@ import { MessageType, Middleware, RpcConnectionContext, RpcContext } from "./rpc"; | ||
private runningCalls; | ||
private lastResponseAt; | ||
private lastSendAt; | ||
open(socket: Socket): void; | ||
@@ -37,0 +37,0 @@ private trackMessageReceived; |
@@ -80,3 +80,3 @@ "use strict"; | ||
this.runningCalls = {}; | ||
this.lastResponseAt = 0; | ||
this.lastSendAt = 0; | ||
this.resolveDisconnect = function () { }; | ||
@@ -121,3 +121,2 @@ this.sendPing = function () { return __awaiter(_this, void 0, void 0, function () { | ||
} | ||
_this.lastResponseAt = Date.now(); | ||
_this.flushPendingCalls(); | ||
@@ -267,2 +266,3 @@ }); | ||
} | ||
this.lastSendAt = Date.now(); | ||
var data = utils_1.message.apply(void 0, __spreadArrays([type, id], params)); | ||
@@ -303,3 +303,3 @@ this.listeners.messageOut(data); | ||
if (this.delayCalls) { | ||
var delay = this.lastResponseAt + this.delayCalls - Date.now(); | ||
var delay = this.lastSendAt + this.delayCalls - Date.now(); | ||
if (delay > 0) { | ||
@@ -317,2 +317,3 @@ setTimeout(function () { return _this.flushPendingCalls(); }, delay); | ||
if (call.type == "ping") { | ||
this.lastSendAt = Date.now(); | ||
this.runningCalls[PING_MESSAGE_ID] = call; | ||
@@ -359,3 +360,2 @@ this.socket.ping(JSON.stringify(call.params)); | ||
} | ||
this.lastResponseAt = Date.now(); | ||
this.flushPendingCalls(); | ||
@@ -362,0 +362,0 @@ }; |
{ | ||
"name": "@push-rpc/core", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"main": "dist/index.js", | ||
@@ -20,3 +20,3 @@ "types": "dist/index.d.ts", | ||
}, | ||
"gitHead": "a57efb1c186ea965d8c23c132b1500f273ecf1c2" | ||
"gitHead": "65172764a34fac7afc69fe905a36137b88051d75" | ||
} |
@@ -53,3 +53,3 @@ import {LocalTopicImpl} from "./local" | ||
private lastResponseAt: number = 0 | ||
private lastSendAt: number = 0 | ||
@@ -78,3 +78,2 @@ open(socket: Socket) { | ||
this.lastResponseAt = Date.now() | ||
this.flushPendingCalls() | ||
@@ -258,2 +257,4 @@ }) | ||
send(type: MessageType, id: string, ...params) { | ||
this.lastSendAt = Date.now() | ||
const data = message(type, id, ...params) | ||
@@ -298,3 +299,3 @@ this.listeners.messageOut(data) | ||
if (this.delayCalls) { | ||
const delay = this.lastResponseAt + this.delayCalls - Date.now() | ||
const delay = this.lastSendAt + this.delayCalls - Date.now() | ||
@@ -316,2 +317,4 @@ if (delay > 0) { | ||
if (call.type == "ping") { | ||
this.lastSendAt = Date.now() | ||
this.runningCalls[PING_MESSAGE_ID] = call | ||
@@ -364,3 +367,2 @@ this.socket.ping(JSON.stringify(call.params)) | ||
this.lastResponseAt = Date.now() | ||
this.flushPendingCalls() | ||
@@ -367,0 +369,0 @@ } |
@@ -149,3 +149,3 @@ import {createTestClient, startTestServer} from "./testUtils" | ||
it("wait some time before sending next call", async () => { | ||
it("delay before sending next call", async () => { | ||
let resolveCall | ||
@@ -173,5 +173,2 @@ let callNo | ||
await new Promise(r => setTimeout(r, 100)) | ||
assert.equal(callNo, 1) | ||
await new Promise(r => setTimeout(r, 100)) // 200 ms from last response | ||
@@ -181,2 +178,33 @@ assert.equal(callNo, 2) | ||
}) | ||
it("wait before sending next call after receiving response", async () => { | ||
let callNo | ||
const server = await startTestServer({ | ||
async call(_callNo) { | ||
callNo = _callNo | ||
}, | ||
}) | ||
const client = await createTestClient(0, { | ||
syncRemoteCalls: true, | ||
delayCalls: 150, | ||
local: { | ||
async test() { | ||
console.log("Client local") | ||
}, | ||
}, | ||
}) | ||
const remoteClient = server.getRemote(server.getConnectedIds()[0]) | ||
await remoteClient.test() | ||
client.call(1) | ||
await new Promise(r => setTimeout(r, 100)) | ||
assert.isUndefined(callNo) | ||
await new Promise(r => setTimeout(r, 100)) // 200 ms since response | ||
assert.equal(callNo, 1) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
153179
4080