Documentation
¶
Overview ¶
This is the main executable package
This file implements a priority queue with per-user rate limiting for outgoing Telegram messages.
Producers call enqueueMessage which pushes packets into a buffered channel. A single sender goroutine owns a packetHeap, drains all pending packets from the channel into the heap each iteration, and sends the highest-priority ready packet.
The heap is a min-heap ordered by:
- readyAt time — earlier is better. Zero (default) means ready immediately. Rate-limited chats get a future readyAt and sink to the bottom.
- priority — lower value wins (db.PriorityHigh < db.PriorityLow)
- push sequence — global sequence counter
Per-user rate limiting: After each send, setReadyAt marks the chat as unavailable for 1 second. The heap re-sorts so other chats' packets flow while the rate-limited chat waits.
Cleanup: maxReadyAt entries are removed after they expire. A cleanup heap (min-heap by readyAt time) tracks per-chatID entries. Superseded entries (seq mismatch) are skipped. When an entry expires, its map entry is deleted and heap.Fix restores affected packets' heap positions.