Skip to main content

spawn_clipboard_read

Function spawn_clipboard_read 

Source
pub fn spawn_clipboard_read(scope: ClipboardRead) -> Receiver<Option<Clipboard>> 
Expand description

Starts one background clipboard read on a detached thread, delivering the result through the returned one-shot channel.

Ok(None) means the clipboard was empty or unreadable; a channel closed without a value means the reader thread could not be spawned, so callers never wait on a read that will not happen.

The reader is deliberately a detached thread, not a tokio blocking task: a running blocking task cannot be aborted and would stall runtime shutdown behind a wedged native clipboard, while a detached thread dies with the process. Backend subprocesses cap themselves at 5–8 s, but a hung native handle can outlive that — pair the receiver with a deadline and drop it to abandon the read.

Examples found in repository?
examples/chat/main.rs (line 45)
43	fn start(scope: ClipboardRead) -> Self {
44		Self {
45			clipboard: paste::spawn_clipboard_read(scope),
46			scope,
47			abandon_at: Instant::now() + PASTE_READ_TIMEOUT,
48		}
49	}