Crate powerpack_detach
source ·Expand description
Provides a way to background a process from an Alfred workflow.
It does this by forking the process and closing the stdin/stdout/stderr file
descriptors for the child process. This makes sure Alfred does not block on
the process. Calling spawn
does the following:
- In the parent:
- Returns immediately.
- In the child:
- Detaches the stdin/stdout/stderr file descriptors.
- Sets up a panic hook that logs an error on panic.
- Executes the given function.
- Exit the process.
💡 Note
Depending on your Alfred workflow settings Alfred might execute your workflow many times in a short space of time. It can be useful to make sure only one child process is running at a time by first acquiring a file mutex in the spawned function.
Examples
powerpack::detach::spawn(|| {
// some expensive operation that shouldn't block Alfred
//
// e.g. fetch and cache a remote resource
}).expect("forked child process");
Functions
- Execute a function in a child process.