forked from StrafesNET/strafe-client
make that shit compile
This commit is contained in:
parent
8000d1db29
commit
928654c7df
@ -17,9 +17,7 @@ impl Worker {
|
|||||||
fn start(self) {
|
fn start(self) {
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
loop {
|
loop {
|
||||||
let (ref lock, ref cvar) = &*self.receiver;
|
match self.receiver.0.lock().recv() {
|
||||||
let task = lock.lock().unwrap().recv();
|
|
||||||
match task {
|
|
||||||
Ok(task) => {
|
Ok(task) => {
|
||||||
println!("Worker {} got a task: {}", self.id, task);
|
println!("Worker {} got a task: {}", self.id, task);
|
||||||
// Process the task
|
// Process the task
|
||||||
@ -69,14 +67,10 @@ fn main() {
|
|||||||
if !is_worker_active {
|
if !is_worker_active {
|
||||||
// If the worker is done, signal it to process a new task
|
// If the worker is done, signal it to process a new task
|
||||||
is_active.store(true, Ordering::SeqCst);
|
is_active.store(true, Ordering::SeqCst);
|
||||||
let (ref lock, ref cvar) = &*receiver;
|
thread::sleep(std::time::Duration::from_secs(2));
|
||||||
cvar.notify_one();
|
|
||||||
|
|
||||||
// Send a new task
|
// Send a new task
|
||||||
sender.send("New Task".to_string()).unwrap();
|
sender.send("New Task".to_string()).unwrap();
|
||||||
|
|
||||||
// Wait for the worker to finish processing
|
|
||||||
cvar.wait_while(lock.lock(), |&active| active);
|
|
||||||
} else {
|
} else {
|
||||||
println!("Worker is still active. Skipping new task.");
|
println!("Worker is still active. Skipping new task.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user