MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / start_new

Method start_new

crates/cache/src/worker.rs:67–94  ·  view source on GitHub ↗
(cache_config: &CacheConfig)

Source from the content-addressed store, hash-verified

65
66impl Worker {
67 pub(super) fn start_new(cache_config: &CacheConfig) -> Self {
68 let queue_size = match cache_config.worker_event_queue_size() {
69 num if num <= usize::max_value() as u64 => num as usize,
70 _ => usize::max_value(),
71 };
72 let (tx, rx) = sync_channel(queue_size);
73
74 #[cfg(test)]
75 let stats = Arc::new((Mutex::new(WorkerStats::default()), Condvar::new()));
76
77 let worker_thread = WorkerThread {
78 receiver: rx,
79 cache_config: cache_config.clone(),
80 #[cfg(test)]
81 stats: stats.clone(),
82 };
83
84 // when self is dropped, sender will be dropped, what will cause the channel
85 // to hang, and the worker thread to exit -- it happens in the tests
86 // non-tests binary has only a static worker, so Rust doesn't drop it
87 thread::spawn(move || worker_thread.run());
88
89 Self {
90 sender: tx,
91 #[cfg(test)]
92 stats,
93 }
94 }
95
96 pub(super) fn on_cache_get_async(&self, path: impl AsRef<Path>) {
97 let event = CacheEvent::OnCacheGet(path.as_ref().to_path_buf());

Callers

nothing calls this directly

Calls 4

spawnFunction · 0.85
newFunction · 0.50
cloneMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected