Skip to content

Commit

Permalink
rename setter methods (#42)
Browse files Browse the repository at this point in the history
This renames the setters on workers and schedulers to follow the
standard convention.

While this is a breaking change, we don't plan to follow proper semver
until 0.1.x, so rather than deprecate we've simply renamed.
  • Loading branch information
maxcountryman authored Oct 28, 2024
1 parent 0a44375 commit 707f284
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
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

0 comments on commit 707f284

Please sign in to comment.