socket-function 1.1.10 → 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/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?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "1.1.10",
3
+ "version": "1.1.11",
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);