diff options
author | Aleksey Kladov <[email protected]> | 2019-01-15 12:45:48 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-15 12:45:48 +0000 |
commit | fedd320cf284ec5d489e62bf809277cedd9f60ac (patch) | |
tree | ba684c9ce0161079026b47b17d933d8c845476e2 /crates/ra_db | |
parent | dd45697e5396d4a6ac8e838e1f4f510c960b9c43 (diff) |
check_canceled does not return Result
Diffstat (limited to 'crates/ra_db')
-rw-r--r-- | crates/ra_db/src/lib.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 0e7f32e66..8473fc050 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs | |||
@@ -21,11 +21,23 @@ pub use crate::{ | |||
21 | }; | 21 | }; |
22 | 22 | ||
23 | pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe { | 23 | pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe { |
24 | fn check_canceled(&self) -> Cancelable<()> { | 24 | /// Aborts current query if there are pending changes. |
25 | /// | ||
26 | /// rust-analyzer needs to be able to answer semantic questions about the | ||
27 | /// code while the code is being modified. A common problem is that a | ||
28 | /// long-running query is being calculated when a new change arrives. | ||
29 | /// | ||
30 | /// We can't just apply the change immediately: this will cause the pending | ||
31 | /// query to see inconsistent state (it will observe an absence of | ||
32 | /// repeatable read). So what we do is we **cancel** all pending queries | ||
33 | /// before applying the change. | ||
34 | /// | ||
35 | /// We implement cancellation by panicking with a special value and catching | ||
36 | /// it on the API boundary. Salsa explicitly supports this use-case. | ||
37 | fn check_canceled(&self) { | ||
25 | if self.salsa_runtime().is_current_revision_canceled() { | 38 | if self.salsa_runtime().is_current_revision_canceled() { |
26 | Canceled::throw() | 39 | Canceled::throw() |
27 | } | 40 | } |
28 | Ok(()) | ||
29 | } | 41 | } |
30 | 42 | ||
31 | fn catch_canceled<F: FnOnce(&Self) -> T + panic::UnwindSafe, T>( | 43 | fn catch_canceled<F: FnOnce(&Self) -> T + panic::UnwindSafe, T>( |