MCPcopy Create free account
hub / github.com/base/triedb / defer

Method defer

src/executor/threadpool.rs:21–38  ·  view source on GitHub ↗
(&self, f: F)

Source from the content-addressed store, hash-verified

19
20impl Executor for ThreadPool {
21 fn defer<F, T>(&self, f: F) -> Future<T>
22 where
23 F: FnOnce() -> T + Send + 'static,
24 T: Send + Sync + 'static,
25 {
26 let sender_future = Future::pending();
27 let receiver_future = sender_future.clone();
28
29 self.spawn(move || {
30 // Create the guard panic first, then run the closure. The guard will be dropped at the
31 // end of this scope. If the function succeeds, the guard won't do anything; if it
32 // panics, the guard's `Drop` implementation will poison the future.
33 let _guard = PanicGuard { future: &sender_future };
34 sender_future.complete(f())
35 });
36
37 receiver_future
38 }
39}
40
41/// A "guard" to detect if this thread panics, and poison the `Future` in that case.

Callers 2

deferFunction · 0.45
poisoningFunction · 0.45

Calls 2

cloneMethod · 0.80
completeMethod · 0.80

Tested by 2

deferFunction · 0.36
poisoningFunction · 0.36