Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename setter methods #42

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,10 +1404,10 @@ where
let job = self.clone();

let mut worker = Worker::new(queue.clone(), job.clone());
worker = worker.shutdown_token(shutdown_token.clone());
worker.set_shutdown_token(shutdown_token.clone());

let mut scheduler = Scheduler::new(queue, job);
scheduler = scheduler.shutdown_token(shutdown_token.clone());
scheduler.set_shutdown_token(shutdown_token.clone());

// Spawn the tasks using `tokio::spawn` to decouple them from polling the
// `Future`.
Expand Down
9 changes: 4 additions & 5 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,21 @@ impl<T: Task> Scheduler<T> {
/// # .build()
/// # .await?;
/// # let task = ExampleTask;
/// # let scheduler = Scheduler::new(queue, task);
/// # let mut scheduler = Scheduler::new(queue, task);
/// # /*
/// let scheduler = { /* A `Scheduler`. */ };
/// let mut scheduler = { /* A `Scheduler`. */ };
/// # */
/// #
///
/// // Set a custom cancellation token.
/// let token = CancellationToken::new();
/// scheduler.shutdown_token(token);
/// scheduler.set_shutdown_token(token);
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// # });
/// # }
/// ```
pub fn shutdown_token(mut self, shutdown_token: CancellationToken) -> Self {
pub fn set_shutdown_token(&mut self, shutdown_token: CancellationToken) {
self.shutdown_token = shutdown_token;
self
}

/// Cancels the shutdown token causing the scheduler to exit.
Expand Down
18 changes: 8 additions & 10 deletions src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,21 +271,20 @@ impl<T: Task + Sync> Worker<T> {
/// # .build()
/// # .await?;
/// # let task = ExampleTask;
/// # let worker = Worker::new(queue, task);
/// # let mut worker = Worker::new(queue, task);
/// # /*
/// let worker = { /* A `Worker`. */ };
/// let mut worker = { /* A `Worker`. */ };
/// # */
/// #
///
/// // Set a fixed concurrency limit.
/// worker.concurrency_limit(32);
/// worker.set_concurrency_limit(32);
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// # });
/// # }
/// ```
pub fn concurrency_limit(mut self, concurrency_limit: usize) -> Self {
pub fn set_concurrency_limit(&mut self, concurrency_limit: usize) {
self.concurrency_limit = concurrency_limit;
self
}

/// Sets the shutdown token.
Expand Down Expand Up @@ -320,22 +319,21 @@ impl<T: Task + Sync> Worker<T> {
/// # .build()
/// # .await?;
/// # let task = ExampleTask;
/// # let worker = Worker::new(queue, task);
/// # let mut worker = Worker::new(queue, task);
/// # /*
/// let worker = { /* A `Worker`. */ };
/// let mut worker = { /* A `Worker`. */ };
/// # */
/// #
///
/// // Set a custom cancellation token.
/// let token = CancellationToken::new();
/// worker.shutdown_token(token);
/// worker.set_shutdown_token(token);
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// # });
/// # }
/// ```
pub fn shutdown_token(mut self, shutdown_token: CancellationToken) -> Self {
pub fn set_shutdown_token(&mut self, shutdown_token: CancellationToken) {
self.shutdown_token = shutdown_token;
self
}

/// Cancels the shutdown token and begins a graceful shutdown of in-progress
Expand Down