hocuspocus
hocuspocus copied to clipboard
Prevent setTimeout buildup during frequent document updates
Addresses https://github.com/ueberdosis/hocuspocus/issues/854
When making many edits to the same document within the disconnectTimeout window (1000ms by default), it's possible to stack a large number of redundant setTimeout calls. This tracks and clears any pending Timeouts when new hooks are fired against the same document.
in the case of afterStoreDocument, we immediately resolve the promise so that outstanding hooks complete. In the case of onDisconnect, we simply clear the timeout, since we'll set a new delayed disconnect call.