Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Add debounce to restart watchers #1040

Merged
merged 1 commit into from
Feb 26, 2024
Merged

Add debounce to restart watchers #1040

merged 1 commit into from
Feb 26, 2024

Conversation

vinistock
Copy link
Member

Motivation

One thing that causes frustration is that when pulling and switching branches, we sometimes reboot the server too quickly and it results in errors or multiple unnecessary restarts.

There is also a race condition between the rebase and the lockfile watchers. If you rebase a branch and get an updated lockfile and a rebase conflict at the same exact time, there's no way to tell if which watcher will fire first. We could end up in a situation where we trigger the lockfile reboot and only after set the rebase flag to prevent further restarts, which is too late.

I think adding a debounce to our restart watchers will result in a smoother experience.

Implementation

  1. Created a debounce function. It receives another function and a delay as arguments, which then creates a version of that function that is debounced by the specified delay. The final function is only invoked if the timer runs out and all other invocations that occur before then are cancelled automatically
  2. Used the debounce function in our lockfile restarts

Manual Tests

  1. Start the LSP on this branch
  2. Make a change to the lockfile of a project
  3. Verify that the LSP doesn't restart immediately, but rather waits a couple of seconds and then restarts properly

@vinistock vinistock self-assigned this Feb 21, 2024
@vinistock vinistock requested a review from a team as a code owner February 21, 2024 18:09
Copy link
Contributor

@egiurleo egiurleo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clever! Tested manually and verified that it took a few seconds for the LSP to restart.

@vinistock vinistock merged commit 0aa9e97 into main Feb 26, 2024
10 checks passed
@vinistock vinistock deleted the vs/add_restart_delay branch February 26, 2024 19:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants