Skip to content

Commit

Permalink
sync wait for service factories to be ready
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Nov 4, 2021
1 parent 7d98247 commit 15279ea
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion actix-server/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ impl ServerWorker {
// get actix system context if it is set
let sys = System::try_current();

// TODO: wait for server startup with sync channel
// service factories initialization channel
let (factory_tx, factory_rx) = std::sync::mpsc::sync_channel(1);

std::thread::Builder::new()
.name(format!("actix-server worker {}", idx))
Expand Down Expand Up @@ -350,6 +351,8 @@ impl ServerWorker {
}
};

factory_tx.send(()).unwrap();

// a third spawn to make sure ServerWorker runs as non boxed future.
spawn(ServerWorker {
rx,
Expand All @@ -369,6 +372,9 @@ impl ServerWorker {
})
.expect("worker thread error/panic");

// wait for service factories initialization
factory_rx.recv().unwrap();

Ok(handle_pair(idx, tx1, tx2, counter))
}

Expand Down

0 comments on commit 15279ea

Please sign in to comment.