socket-function 1.1.9 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SocketFunction.d.ts +1 -0
- package/SocketFunction.ts +1 -0
- package/index.d.ts +7 -2
- package/package.json +1 -1
- package/src/CallFactory.ts +3 -3
- package/src/batching.d.ts +6 -2
- package/src/batching.ts +6 -4
package/SocketFunction.d.ts
CHANGED
|
@@ -64,6 +64,7 @@ export declare class SocketFunction {
|
|
|
64
64
|
private static socketCache;
|
|
65
65
|
static rehydrateSocketCaller<Controller>(socketRegistered: SocketRegisterType<Controller>, shapeFnc?: () => SocketExposedShape): SocketRegistered<Controller>;
|
|
66
66
|
private static callFromGuid;
|
|
67
|
+
/** Will dedupe callbacks, so if you call with the same callback it won't call it multiple times (otherwise it's difficult to manage this, as this only calls on the NEXT callback). */
|
|
67
68
|
static onNextDisconnect(nodeId: string, callback: () => void): void;
|
|
68
69
|
static getLastDisconnectTime(nodeId: string): number | undefined;
|
|
69
70
|
static isNodeConnected(nodeId: string): boolean;
|
package/SocketFunction.ts
CHANGED
|
@@ -289,6 +289,7 @@ export class SocketFunction {
|
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
+
/** Will dedupe callbacks, so if you call with the same callback it won't call it multiple times (otherwise it's difficult to manage this, as this only calls on the NEXT callback). */
|
|
292
293
|
public static onNextDisconnect(nodeId: string, callback: () => void) {
|
|
293
294
|
(async () => {
|
|
294
295
|
let factory = await getCallFactory(nodeId);
|
package/index.d.ts
CHANGED
|
@@ -73,6 +73,7 @@ declare module "socket-function/SocketFunction" {
|
|
|
73
73
|
private static socketCache;
|
|
74
74
|
static rehydrateSocketCaller<Controller>(socketRegistered: SocketRegisterType<Controller>, shapeFnc?: () => SocketExposedShape): SocketRegistered<Controller>;
|
|
75
75
|
private static callFromGuid;
|
|
76
|
+
/** Will dedupe callbacks, so if you call with the same callback it won't call it multiple times (otherwise it's difficult to manage this, as this only calls on the NEXT callback). */
|
|
76
77
|
static onNextDisconnect(nodeId: string, callback: () => void): void;
|
|
77
78
|
static getLastDisconnectTime(nodeId: string): number | undefined;
|
|
78
79
|
static isNodeConnected(nodeId: string): boolean;
|
|
@@ -591,8 +592,12 @@ declare module "socket-function/src/batching" {
|
|
|
591
592
|
parallelCount: number;
|
|
592
593
|
callTimeout?: number;
|
|
593
594
|
}, fnc: T): T;
|
|
594
|
-
export declare function runInfinitePoll(delayTime: number, fnc: () => Promise<void> | void
|
|
595
|
-
|
|
595
|
+
export declare function runInfinitePoll(delayTime: number, fnc: () => Promise<void> | void, stopObj?: {
|
|
596
|
+
stop: boolean;
|
|
597
|
+
}): void;
|
|
598
|
+
export declare function runInfinitePollCallAtStart(delayTime: number, fnc: () => Promise<void> | void, stopObj?: {
|
|
599
|
+
stop: boolean;
|
|
600
|
+
}): Promise<void>;
|
|
596
601
|
/** Disables polling, called on shutdown. Blocks until all pending poll loops finish */
|
|
597
602
|
export declare function shutdownPolling(): Promise<void>;
|
|
598
603
|
export declare function retryFunctional<T extends AnyFunction>(fnc: T, config?: {
|
package/package.json
CHANGED
package/src/CallFactory.ts
CHANGED
|
@@ -145,9 +145,9 @@ export async function createCallFactory(
|
|
|
145
145
|
localNodeId
|
|
146
146
|
};
|
|
147
147
|
|
|
148
|
-
let disconnectCallbacks
|
|
148
|
+
let disconnectCallbacks = new Set<() => void>();
|
|
149
149
|
function onNextDisconnect(callback: () => void): void {
|
|
150
|
-
disconnectCallbacks.
|
|
150
|
+
disconnectCallbacks.add(callback);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
let callFactory: CallFactory = {
|
|
@@ -315,7 +315,7 @@ export async function createCallFactory(
|
|
|
315
315
|
}
|
|
316
316
|
|
|
317
317
|
let callbacks = disconnectCallbacks;
|
|
318
|
-
disconnectCallbacks =
|
|
318
|
+
disconnectCallbacks = new Set();
|
|
319
319
|
for (let callback of callbacks) {
|
|
320
320
|
try {
|
|
321
321
|
callback();
|
package/src/batching.d.ts
CHANGED
|
@@ -19,8 +19,12 @@ export declare function runInParallel<T extends (...args: any[]) => Promise<any>
|
|
|
19
19
|
parallelCount: number;
|
|
20
20
|
callTimeout?: number;
|
|
21
21
|
}, fnc: T): T;
|
|
22
|
-
export declare function runInfinitePoll(delayTime: number, fnc: () => Promise<void> | void
|
|
23
|
-
|
|
22
|
+
export declare function runInfinitePoll(delayTime: number, fnc: () => Promise<void> | void, stopObj?: {
|
|
23
|
+
stop: boolean;
|
|
24
|
+
}): void;
|
|
25
|
+
export declare function runInfinitePollCallAtStart(delayTime: number, fnc: () => Promise<void> | void, stopObj?: {
|
|
26
|
+
stop: boolean;
|
|
27
|
+
}): Promise<void>;
|
|
24
28
|
/** Disables polling, called on shutdown. Blocks until all pending poll loops finish */
|
|
25
29
|
export declare function shutdownPolling(): Promise<void>;
|
|
26
30
|
export declare function retryFunctional<T extends AnyFunction>(fnc: T, config?: {
|
package/src/batching.ts
CHANGED
|
@@ -253,10 +253,11 @@ let pendingPolls = new Set<Promise<unknown>>();
|
|
|
253
253
|
|
|
254
254
|
export function runInfinitePoll(
|
|
255
255
|
delayTime: number,
|
|
256
|
-
fnc: () => Promise<void> | void
|
|
256
|
+
fnc: () => Promise<void> | void,
|
|
257
|
+
stopObj?: { stop: boolean; }
|
|
257
258
|
) {
|
|
258
259
|
void (async () => {
|
|
259
|
-
while (pollingRunning) {
|
|
260
|
+
while (!stopObj?.stop && pollingRunning) {
|
|
260
261
|
await delay(delayTime);
|
|
261
262
|
if (!pollingRunning) break;
|
|
262
263
|
await runPollFnc(fnc);
|
|
@@ -266,13 +267,14 @@ export function runInfinitePoll(
|
|
|
266
267
|
|
|
267
268
|
export async function runInfinitePollCallAtStart(
|
|
268
269
|
delayTime: number,
|
|
269
|
-
fnc: () => Promise<void> | void
|
|
270
|
+
fnc: () => Promise<void> | void,
|
|
271
|
+
stopObj?: { stop: boolean; }
|
|
270
272
|
) {
|
|
271
273
|
try {
|
|
272
274
|
return await fnc();
|
|
273
275
|
} finally {
|
|
274
276
|
void (async () => {
|
|
275
|
-
while (
|
|
277
|
+
while (!stopObj?.stop && pollingRunning) {
|
|
276
278
|
await delay(delayTime);
|
|
277
279
|
if (!pollingRunning) break;
|
|
278
280
|
await runPollFnc(fnc);
|