socket-function 1.1.10 → 1.1.12

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/index.d.ts CHANGED
@@ -592,8 +592,12 @@ declare module "socket-function/src/batching" {
592
592
  parallelCount: number;
593
593
  callTimeout?: number;
594
594
  }, fnc: T): T;
595
- export declare function runInfinitePoll(delayTime: number, fnc: () => Promise<void> | void): void;
596
- export declare function runInfinitePollCallAtStart(delayTime: number, fnc: () => Promise<void> | void): Promise<void>;
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>;
597
601
  /** Disables polling, called on shutdown. Blocks until all pending poll loops finish */
598
602
  export declare function shutdownPolling(): Promise<void>;
599
603
  export declare function retryFunctional<T extends AnyFunction>(fnc: T, config?: {
@@ -1064,6 +1068,7 @@ declare module "socket-function/src/nodeCache" {
1064
1068
  export declare function registerNodeClient(callFactory: CallFactory): void;
1065
1069
  export declare function getCreateCallFactory(nodeId: string): MaybePromise<CallFactory>;
1066
1070
  export declare function getCallFactory(nodeId: string): MaybePromise<CallFactory | undefined>;
1071
+ export declare function debugGetAllCallFactories(): CallFactory[];
1067
1072
  export declare function resetAllNodeCallFactories(): void;
1068
1073
  export declare function countOpenConnections(): number;
1069
1074
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
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): void;
23
- export declare function runInfinitePollCallAtStart(delayTime: number, fnc: () => Promise<void> | void): Promise<void>;
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 (true) {
277
+ while (!stopObj?.stop && pollingRunning) {
276
278
  await delay(delayTime);
277
279
  if (!pollingRunning) break;
278
280
  await runPollFnc(fnc);
@@ -20,5 +20,6 @@ export declare function getNodeIdDomainMaybeUndefined(nodeId: string): string |
20
20
  export declare function registerNodeClient(callFactory: CallFactory): void;
21
21
  export declare function getCreateCallFactory(nodeId: string): MaybePromise<CallFactory>;
22
22
  export declare function getCallFactory(nodeId: string): MaybePromise<CallFactory | undefined>;
23
+ export declare function debugGetAllCallFactories(): CallFactory[];
23
24
  export declare function resetAllNodeCallFactories(): void;
24
25
  export declare function countOpenConnections(): number;
package/src/nodeCache.ts CHANGED
@@ -89,6 +89,17 @@ export function getCallFactory(nodeId: string): MaybePromise<CallFactory | undef
89
89
  return nodeCache.get(nodeId);
90
90
  }
91
91
 
92
+ export function debugGetAllCallFactories(): CallFactory[] {
93
+ let result: CallFactory[] = [];
94
+ for (let [key, value] of nodeCache.entries()) {
95
+ if (value instanceof Promise) {
96
+ continue;
97
+ }
98
+ result.push(value);
99
+ }
100
+ return result;
101
+ }
102
+
92
103
  export function resetAllNodeCallFactories() {
93
104
  // Needs to be done if you want to reset authentication. Outstanding calls still work,
94
105
  // but new calls use new factories (and connections).