MCPcopy
hub / github.com/msgbyte/tianji / add

Method add

packages/client-sdk/src/utils/batch-manager.ts:51–79  ·  view source on GitHub ↗

* Add item to batch queue

(type: string, payload: T)

Source from the content-addressed store, hash-verified

49 * Add item to batch queue
50 */
51 add(type: string, payload: T): void {
52 if (this.options.disableBatch) {
53 // Fire and forget, but catch errors to prevent unhandled promise rejection
54 this.options.onSingleSend({ type, payload }).catch((error) => {
55 console.error('Error in onSingleSend:', error);
56 });
57 return;
58 }
59
60 this.queue.push({ type, payload });
61
62 // Send immediately if queue reaches the limit
63 if (this.queue.length >= (this.options.maxBatchSize || 100)) {
64 // Fire and forget, but catch errors to prevent unhandled promise rejection
65 this.flush().catch((error) => {
66 console.error('Error in auto-flush:', error);
67 });
68 return;
69 }
70
71 // Start timer only if not already running (throttling behavior)
72 if (!this.timer) {
73 this.timer = setTimeout(() => {
74 this.sendBatch().catch((error) => {
75 console.error('Error in scheduled batch send:', error);
76 });
77 }, this.options.batchDelay);
78 }
79 }
80
81 /**
82 * Send batch request

Callers 15

createTrackerCoreFunction · 0.95
scriptFunction · 0.80
GluestackUIProviderFunction · 0.80
sendRequestFunction · 0.80
sendWebsiteRequestFunction · 0.80
createDateUnitFnFunction · 0.80
fillPageviewsTrendFunction · 0.80
PageComponentFunction · 0.80
handleMouseOverFunction · 0.80
useThemeInitFunction · 0.80
processInsightsDataFunction · 0.80
createDateUnitFnFunction · 0.80

Calls 4

flushMethod · 0.95
sendBatchMethod · 0.95
catchMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected