Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore events during grace period after task start #233

Merged
merged 4 commits into from
Oct 8, 2024
Merged

Conversation

Canop
Copy link
Owner

@Canop Canop commented Oct 7, 2024

When some file events are received:

  • the task child process waits for 5ms before starting the real task
  • during the same period, file events are discarded

The goal is to prevent

  • the cargo job from running with not all changes
  • a bunch of quasi-simultaneous file changes from triggerring more than one cargo execution

Downside is that you have to wait for 5ms more before the computation result is displayed after a save.

The delay can be removed or modified in the preferences. Eg grace_period="15ms" or grace_period="none".

May fix #222

@Canop Canop merged commit 7b6491a into main Oct 8, 2024
@narpfel
Copy link
Contributor

narpfel commented Oct 8, 2024

Thanks, this works well for me.

  • the task child process waits for 5ms before starting the real task

I’m not sure if that’s really necessary. Yes, there technically is a race between the text editor writing the file and the triggered job reading the file, however I’d expect that in the vast majority of cases, the text editor is faster. Just starting cargo through the rustup shim takes ~50ms (rust-lang/rustup#2626), so the sleep here

bacon/src/exec/executor.rs

Lines 111 to 116 in b8cb636

// before starting the command, we wait some time, so that a bunch
// of quasi-simultaneous file events can be finished before the command
// starts (during this time, no other command is started by bacon in app.rs)
if !grace_period.is_zero() {
thread::sleep(grace_period.duration);
}
is probably not necessary. On the other hand, a couple of milliseconds are probably not noticeable.

@Canop
Copy link
Owner Author

Canop commented Oct 8, 2024

I first pushed the PR without this sleep, then I decided I didn't want to have race conditions when cargo becomes faster and I'm sure nobody will be annoyed by those 5 or 10 ms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vim double-triggers bacon v2.21.0 when saving a file
2 participants