For complex integrations, you can signal the beginning and end of high-activity periods (like a Git update) using state-enter and state-leave. The subscribe command allows you to control how notifications are handled during these states using defer or drop.
defer
Specifies a list of state names to pause notifications. When a matching state is entered via state-enter, Watchman sends a notification containing the state-enter metadata and then holds all files payloads. Once the state is vacated via state-leave (or the client disconnects), Watchman sends a state-leave notification and flushes all accumulated notifications that occurred during the state.
drop
Specifies a list of state names to discard notifications. It behaves like defer, but instead of buffering notifications, it 'fast-forwards' the stream to the clock of the state-leave command. This effectively suppresses all notifications generated between the state-enter and state-leave events.
Best Practice: If using multiple overlapping states, it is recommended to use drop for all states and then issue manual queries with since terms bounded by the clock fields from the subscription state PDUs to ensure no data is missed.
// Example: Deferring notifications for a specific state
["subscribe", "/path/to/root", "mysubscriptionname", {
"defer": ["mystatename"],
"fields": ["name"]
}]
// Example: Dropping notifications for a specific state
["subscribe", "/path/to/root", "mysubscriptionname", {
"drop": ["mystatename"],
"fields": ["name"]
}]