bunnyquery 1.0.1 → 1.0.2
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/bunnyquery.js +11 -0
- package/package.json +1 -1
package/bunnyquery.js
CHANGED
|
@@ -1089,7 +1089,17 @@
|
|
|
1089
1089
|
_schedulePendingPoll() {
|
|
1090
1090
|
if (this.pendingTimer) clearTimeout(this.pendingTimer);
|
|
1091
1091
|
if (!this._anyPending()) return;
|
|
1092
|
+
// Bail if a poll is already in flight — its `finally` will
|
|
1093
|
+
// schedule the next one. Without this guard, any caller that
|
|
1094
|
+
// fires while we're awaiting `getChatHistory` (e.g. another
|
|
1095
|
+
// _sendMessage, _loadFirstHistoryPage, or our own previous
|
|
1096
|
+
// tick whose timer already elapsed) would spawn a second
|
|
1097
|
+
// concurrent poller, and each subsequent cycle would compound
|
|
1098
|
+
// — making the polling appear faster and faster.
|
|
1099
|
+
if (this._pollingPending) return;
|
|
1092
1100
|
this.pendingTimer = setTimeout(async () => {
|
|
1101
|
+
this.pendingTimer = null;
|
|
1102
|
+
this._pollingPending = true;
|
|
1093
1103
|
try {
|
|
1094
1104
|
const res = await getChatHistory(
|
|
1095
1105
|
this.skapi,
|
|
@@ -1110,6 +1120,7 @@
|
|
|
1110
1120
|
} catch (err) {
|
|
1111
1121
|
console.error('[BunnyQuery] pending poll failed', err);
|
|
1112
1122
|
} finally {
|
|
1123
|
+
this._pollingPending = false;
|
|
1113
1124
|
this._schedulePendingPoll();
|
|
1114
1125
|
}
|
|
1115
1126
|
}, DEFAULTS.PENDING_POLL_INTERVAL_MS);
|