@secondlayer/sdk 12.1.0 → 12.2.0

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/dist/index.d.ts CHANGED
@@ -871,6 +871,17 @@ type StreamsEventsConsumeParams<
871
871
  maxPages?: number;
872
872
  maxEmptyPolls?: number;
873
873
  signal?: AbortSignal;
874
+ /**
875
+ * Cuts the empty-poll backoff short: on an empty page, the loop races
876
+ * `emptyBackoffMs` against this promise instead of sleeping the full
877
+ * amount. Pass a function that resolves once when new data MIGHT be
878
+ * available (e.g. a Postgres NOTIFY listener) — it is called fresh on
879
+ * every empty page, never awaited more than once concurrently per page.
880
+ * The backoff timer still runs underneath, so a wake source that never
881
+ * resolves (or a `wake` this call omits) degrades to the same polling
882
+ * behavior as before.
883
+ */
884
+ wake?: () => Promise<void>;
874
885
  };
875
886
  /**
876
887
  * One yielded page from {@link StreamsClient.consume} — the
package/dist/index.js CHANGED
@@ -970,7 +970,10 @@ async function consumeStreamsEvents(opts) {
970
970
  if (mode === "bounded") {
971
971
  return { cursor, pages, emptyPolls };
972
972
  }
973
- await sleep(emptyBackoffMs, opts.signal);
973
+ await (opts.wake ? Promise.race([
974
+ sleep(emptyBackoffMs, opts.signal),
975
+ opts.wake().catch(() => new Promise(() => {}))
976
+ ]) : sleep(emptyBackoffMs, opts.signal));
974
977
  continue;
975
978
  }
976
979
  return { cursor, pages, emptyPolls };
@@ -2117,7 +2120,8 @@ function createStreamsClient(options) {
2117
2120
  signal: params.signal,
2118
2121
  retryCount: params.retryCount,
2119
2122
  retryDelay: params.retryDelay,
2120
- onError: params.onError
2123
+ onError: params.onError,
2124
+ wake: params.wake
2121
2125
  });
2122
2126
  }
2123
2127
  return {
@@ -3032,5 +3036,5 @@ export {
3032
3036
  verifyWebhookSignature
3033
3037
  };
3034
3038
 
3035
- //# debugId=AE812DACE82FC03C64756E2164756E21
3039
+ //# debugId=0DD763C5B88AC34564756E2164756E21
3036
3040
  //# sourceMappingURL=index.js.map