Skip to content

Commit

Permalink
Improve docs for WorkerBuilder::with_graceful_shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
rustworthy committed Jul 16, 2024
1 parent f0f1dd7 commit b6ca794
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/worker/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ impl<E: 'static> WorkerBuilder<E> {
/// ```no_run
/// # tokio_test::block_on(async {
/// use faktory::{Client, Job, Worker};
/// use std::time::Duration;
/// use tokio_util::sync::CancellationToken;
/// use tokio::time::sleep;
///
/// Client::connect(None)
/// .await
Expand All @@ -133,8 +135,15 @@ impl<E: 'static> WorkerBuilder<E> {
/// // start consuming
/// let jh = tokio::spawn(async move { w.run(&["default"]).await });
///
/// // verify the consumer thread has not finished
/// sleep(Duration::from_secs(2)).await;
/// assert!(!jh.is_finished());
///
/// // send a signal to eventually return control (upon graceful shutdown)
/// token.cancel();
///
/// // learn the stop reason and the number of workers that were still running
/// let (_stop_reason, _nrunning) = jh.await.expect("joined ok").unwrap();
/// # });
/// ```
pub fn with_graceful_shutdown<F>(mut self, signal: F) -> Self
Expand Down
2 changes: 2 additions & 0 deletions tests/real/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,8 @@ async fn test_shutdown_signals_handling() {
cl.enqueue(j).await.unwrap();
rx_for_test_purposes.recv().await;

assert!(!jh.is_finished());

// ... immediately signal to return control
token.cancel();

Expand Down

0 comments on commit b6ca794

Please sign in to comment.