aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db/src/cancellation.rs
diff options
context:
space:
mode:
authorMarcus Klaas de Vries <[email protected]>2019-01-08 23:47:12 +0000
committerMarcus Klaas de Vries <[email protected]>2019-01-09 00:17:09 +0000
commit0b8fbb4fad97d2980f0070a23f5365a5ed887e2a (patch)
tree4e1cd7f26641c65d809e1a0a6943c77ccbe562d5 /crates/ra_db/src/cancellation.rs
parentf8261d611a60e99bc188022773f84912972208d2 (diff)
Fix typos in ARCHITECTURE.md and a number of crates
specifically: gen_lsp_server, ra_arena, ra_cli, ra_db, ra_hir
Diffstat (limited to 'crates/ra_db/src/cancellation.rs')
-rw-r--r--crates/ra_db/src/cancellation.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/crates/ra_db/src/cancellation.rs b/crates/ra_db/src/cancellation.rs
new file mode 100644
index 000000000..8d38eebfb
--- /dev/null
+++ b/crates/ra_db/src/cancellation.rs
@@ -0,0 +1,44 @@
1//! Utility types to support cancellation.
2//!
3//! In a typical IDE use-case, requests and modification happen concurrently, as
4//! in the following scenario:
5//!
6//! * user types a character,
7//! * a syntax highlighting process is started
8//! * user types next character, while syntax highlighting *is still in
9//! progress*.
10//!
11//! In this situation, we want to react to modification as quickly as possible.
12//! At the same time, in-progress results are not very interesting, because they
13//! are invalidated by the edit anyway. So, we first cancel all in-flight
14//! requests, and then apply modification knowing that it won't interfere with
15//! any background processing (this bit is handled by salsa, see the
16//! `BaseDatabase::check_canceled` method).
17
18/// An "error" signifing that the operation was canceled.
19#[derive(Clone, PartialEq, Eq, Hash)]
20pub struct Canceled {
21 _private: (),
22}
23
24pub type Cancelable<T> = Result<T, Canceled>;
25
26impl Canceled {
27 pub(crate) fn new() -> Canceled {
28 Canceled { _private: () }
29 }
30}
31
32impl std::fmt::Display for Canceled {
33 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34 fmt.write_str("canceled")
35 }
36}
37
38impl std::fmt::Debug for Canceled {
39 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40 write!(fmt, "Canceled")
41 }
42}
43
44impl std::error::Error for Canceled {}