pub struct ThreadLooper { /* private fields */ }
Expand description
The ThreadLooper
struct is designed for managing a looping background thread.
This struct provides functionality to start, manage, and terminate a looping background thread. It is useful for tasks that need to run continuously in the background until explicitly stopped.
§Fields
status
: AnArc<AtomicBool>
indicating whether the looper is active.thread
: ACell
containing anOption<thread::JoinHandle<()>>
for the background thread.termination
: AnArc<AtomicBool>
indicating whether the looper should be terminated.
Implementations§
Source§impl ThreadLooper
impl ThreadLooper
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance of ThreadLooper
.
Initializes the status and termination flags to false
and sets the thread handle to None
.
§Returns
A new instance of ThreadLooper
.
Sourcepub fn start<F>(&self, function: F)
pub fn start<F>(&self, function: F)
Starts the looper with the given function.
If the looper is not already active, this method will start the background thread and run the provided function in a loop.
§Type Parameters
F
: The type of the function to execute in the loop.
§Arguments
function
: The function to be executed in the background thread.
Auto Trait Implementations§
impl !Freeze for ThreadLooper
impl !RefUnwindSafe for ThreadLooper
impl Send for ThreadLooper
impl !Sync for ThreadLooper
impl Unpin for ThreadLooper
impl !UnwindSafe for ThreadLooper
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more