@push-rpc/core
Advanced tools
Comparing version 1.5.1 to 1.5.2
@@ -22,2 +22,3 @@ import { Middleware, RpcConnectionContext } from "./rpc"; | ||
reconnect: boolean; | ||
reconnectDelay: number; | ||
createContext(): RpcConnectionContext; | ||
@@ -24,0 +25,0 @@ localMiddleware: Middleware; |
@@ -65,2 +65,3 @@ "use strict"; | ||
reconnect: false, | ||
reconnectDelay: 0, | ||
createContext: function () { return ({ remoteId: null }); }, | ||
@@ -97,6 +98,6 @@ localMiddleware: function (ctx, next, params, messageType) { return next(params); }, | ||
}; | ||
return (opts.reconnect ? startConnectionLoop : connect)(session, createSocket, opts.listeners, client).then(function () { return client; }); | ||
return (opts.reconnect ? startConnectionLoop : connect)(session, createSocket, opts.listeners, client, opts.reconnectDelay).then(function () { return client; }); | ||
} | ||
exports.createRpcClient = createRpcClient; | ||
function startConnectionLoop(session, createSocket, listeners, client) { | ||
function startConnectionLoop(session, createSocket, listeners, client, reconnectDelay) { | ||
return new Promise(function (resolve) { | ||
@@ -113,8 +114,10 @@ var onFirstConnection = resolve; | ||
onFirstConnection = function () { }; | ||
}, errorDelay, client); | ||
}, errorDelay, client, reconnectDelay); | ||
}); | ||
} | ||
function connectionLoop(session, createSocket, listeners, resolve, errorDelay, client) { | ||
function connectionLoop(session, createSocket, listeners, resolve, errorDelay, client, reconnectDelay) { | ||
function reconnect() { | ||
var timer = setTimeout(function () { return connectionLoop(session, createSocket, listeners, resolve, errorDelay, client); }, errorDelay.value); | ||
var timer = setTimeout(function () { | ||
return connectionLoop(session, createSocket, listeners, resolve, errorDelay, client, reconnectDelay); | ||
}, reconnectDelay + errorDelay.value); | ||
// 2nd and further reconnects are with random delays | ||
@@ -121,0 +124,0 @@ errorDelay.value = Math.round(Math.random() * 15 * 1000); |
@@ -168,3 +168,3 @@ "use strict"; | ||
__spreadArrays(this.queue, Object.values(this.runningCalls)).forEach(function (call) { | ||
call.reject(new Error("Timeout")); | ||
call.reject(new Error("Timeout" + call.type + "-" + call.name)); | ||
}); | ||
@@ -171,0 +171,0 @@ this.queue = []; |
{ | ||
"name": "@push-rpc/core", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"main": "dist/index.js", | ||
@@ -21,3 +21,3 @@ "types": "dist/index.d.ts", | ||
}, | ||
"gitHead": "798275922fa750ff67e4cdd3384fe65f5329e091" | ||
"gitHead": "d77c0c706c833e5230cc5fb7a77225f84e0653b8" | ||
} |
@@ -26,2 +26,3 @@ import {RpcSession} from "./RpcSession" | ||
reconnect: boolean | ||
reconnectDelay: number | ||
createContext(): RpcConnectionContext | ||
@@ -50,2 +51,3 @@ localMiddleware: Middleware | ||
reconnect: false, | ||
reconnectDelay: 0, | ||
createContext: () => ({remoteId: null}), | ||
@@ -97,3 +99,4 @@ localMiddleware: (ctx, next, params, messageType) => next(params), | ||
opts.listeners, | ||
client | ||
client, | ||
opts.reconnectDelay | ||
).then(() => client) | ||
@@ -106,3 +109,4 @@ } | ||
listeners: RpcClientListeners, | ||
client: {disconnectedMark: boolean} | ||
client: {disconnectedMark: boolean}, | ||
reconnectDelay: number | ||
): Promise<void> { | ||
@@ -131,3 +135,4 @@ return new Promise(resolve => { | ||
errorDelay, | ||
client | ||
client, | ||
reconnectDelay | ||
) | ||
@@ -141,10 +146,20 @@ }) | ||
listeners: RpcClientListeners, | ||
resolve, | ||
errorDelay, | ||
client: {disconnectedMark: boolean} | ||
resolve: () => void, | ||
errorDelay: {value: number}, | ||
client: {disconnectedMark: boolean}, | ||
reconnectDelay: number | ||
): void { | ||
function reconnect() { | ||
const timer = setTimeout( | ||
() => connectionLoop(session, createSocket, listeners, resolve, errorDelay, client), | ||
errorDelay.value | ||
() => | ||
connectionLoop( | ||
session, | ||
createSocket, | ||
listeners, | ||
resolve, | ||
errorDelay, | ||
client, | ||
reconnectDelay | ||
), | ||
reconnectDelay + errorDelay.value | ||
) | ||
@@ -151,0 +166,0 @@ |
@@ -131,3 +131,3 @@ import {LocalTopicImpl} from "./local" | ||
;[...this.queue, ...Object.values(this.runningCalls)].forEach(call => { | ||
call.reject(new Error("Timeout")) | ||
call.reject(new Error("Timeout" + call.type + "-" + call.name)) | ||
}) | ||
@@ -134,0 +134,0 @@ |
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
167091
4427