diff options
Diffstat (limited to 'crates/server/src/thread_watcher.rs')
-rw-r--r-- | crates/server/src/thread_watcher.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/crates/server/src/thread_watcher.rs b/crates/server/src/thread_watcher.rs index 98bcdfd6c..74a0a58b7 100644 --- a/crates/server/src/thread_watcher.rs +++ b/crates/server/src/thread_watcher.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | use std::thread; | 1 | use std::thread; |
2 | use crossbeam_channel::{bounded, unbounded, Sender, Receiver}; | ||
2 | use drop_bomb::DropBomb; | 3 | use drop_bomb::DropBomb; |
3 | use Result; | 4 | use Result; |
4 | 5 | ||
@@ -31,3 +32,12 @@ impl ThreadWatcher { | |||
31 | res | 32 | res |
32 | } | 33 | } |
33 | } | 34 | } |
35 | |||
36 | /// Sets up worker channels in a deadlock-avoind way. | ||
37 | /// If one sets both input and output buffers to a fixed size, | ||
38 | /// a worker might get stuck. | ||
39 | pub fn worker_chan<I, O>(buf: usize) -> ((Sender<I>, Receiver<O>), Receiver<I>, Sender<O>) { | ||
40 | let (input_sender, input_receiver) = bounded::<I>(buf); | ||
41 | let (output_sender, output_receiver) = unbounded::<O>(); | ||
42 | ((input_sender, output_receiver), input_receiver, output_sender) | ||
43 | } | ||