Skip to content

Commit

Permalink
Merge pull request #11 from Trivernis/main
Browse files Browse the repository at this point in the history
Remove mutability requirement from SubsystemHandle::start
  • Loading branch information
Finomnis authored Mar 13, 2022
2 parents 36327c9 + 2044eb9 commit 7576b0a
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
Cargo.lock
.idea
2 changes: 1 addition & 1 deletion examples/06_nested_subsystems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use env_logger::{Builder, Env};
use tokio::time::{sleep, Duration};
use tokio_graceful_shutdown::{SubsystemHandle, Toplevel};

async fn subsys1(mut subsys: SubsystemHandle) -> Result<()> {
async fn subsys1(subsys: SubsystemHandle) -> Result<()> {
subsys.start("Subsys2", subsys2);
log::info!("Subsystem1 started.");
subsys.on_shutdown_requested().await;
Expand Down
2 changes: 1 addition & 1 deletion examples/07_nested_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use env_logger::{Builder, Env};
use tokio::time::{sleep, Duration};
use tokio_graceful_shutdown::{SubsystemHandle, Toplevel};

async fn subsys1(mut subsys: SubsystemHandle) -> Result<()> {
async fn subsys1(subsys: SubsystemHandle) -> Result<()> {
subsys.start("Subsys2", subsys2);
log::info!("Subsystem1 started.");
subsys.on_shutdown_requested().await;
Expand Down
2 changes: 1 addition & 1 deletion examples/08_panic_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use env_logger::{Builder, Env};
use tokio::time::{sleep, Duration};
use tokio_graceful_shutdown::{SubsystemHandle, Toplevel};

async fn subsys1(mut subsys: SubsystemHandle) -> Result<()> {
async fn subsys1(subsys: SubsystemHandle) -> Result<()> {
subsys.start("Subsys2", subsys2);
log::info!("Subsystem1 started.");
subsys.on_shutdown_requested().await;
Expand Down
2 changes: 1 addition & 1 deletion examples/11_double_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use env_logger::{Builder, Env};
use tokio::time::{sleep, Duration};
use tokio_graceful_shutdown::{SubsystemHandle, Toplevel};

async fn subsys1(mut subsys: SubsystemHandle) -> Result<()> {
async fn subsys1(subsys: SubsystemHandle) -> Result<()> {
subsys.start("Subsys2", subsys2);
subsys.start("Subsys3", subsys3);
log::info!("Subsystem1 started.");
Expand Down
4 changes: 2 additions & 2 deletions examples/13_partial_shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ async fn subsys3(subsys: SubsystemHandle) -> Result<()> {
Ok(())
}

async fn subsys2(mut subsys: SubsystemHandle) -> Result<()> {
async fn subsys2(subsys: SubsystemHandle) -> Result<()> {
log::info!("Subsys2 started.");
subsys.start("Subsys3", subsys3);
subsys.on_shutdown_requested().await;
log::info!("Subsys2 stopped.");
Ok(())
}

async fn subsys1(mut subsys: SubsystemHandle) -> Result<()> {
async fn subsys1(subsys: SubsystemHandle) -> Result<()> {
// This subsystem shuts down the nested subsystem after 5 seconds.
log::info!("Subsys1 started.");

Expand Down
4 changes: 2 additions & 2 deletions examples/14_partial_shutdown_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ async fn subsys3(subsys: SubsystemHandle) -> Result<()> {
panic!("Subsystem3 threw an error!")
}

async fn subsys2(mut subsys: SubsystemHandle) -> Result<()> {
async fn subsys2(subsys: SubsystemHandle) -> Result<()> {
log::info!("Subsys2 started.");
subsys.start("Subsys3", subsys3);
subsys.on_shutdown_requested().await;
log::info!("Subsys2 stopped.");
Ok(())
}

async fn subsys1(mut subsys: SubsystemHandle) -> Result<()> {
async fn subsys1(subsys: SubsystemHandle) -> Result<()> {
// This subsystem shuts down the nested subsystem after 5 seconds.
log::info!("Subsys1 started.");

Expand Down
6 changes: 3 additions & 3 deletions src/subsystem/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl SubsystemHandle {
/// Ok(())
/// }
///
/// async fn my_subsystem(mut subsys: SubsystemHandle) -> Result<()> {
/// async fn my_subsystem(subsys: SubsystemHandle) -> Result<()> {
/// // start a nested subsystem
/// subsys.start("Nested", nested_subsystem);
///
Expand All @@ -57,7 +57,7 @@ impl SubsystemHandle {
Fut: 'static + Future<Output = Result<()>> + Send,
S: 'static + FnOnce(SubsystemHandle) -> Fut + Send,
>(
&mut self,
&self,
name: &'static str,
subsystem: S,
) -> NestedSubsystem {
Expand Down Expand Up @@ -189,7 +189,7 @@ impl SubsystemHandle {
/// Ok(())
/// }
///
/// async fn subsystem(mut subsys: SubsystemHandle) -> Result<()> {
/// async fn subsystem(subsys: SubsystemHandle) -> Result<()> {
/// // This subsystem waits for one second and then performs a partial shutdown
///
/// // Spawn nested subsystem
Expand Down
22 changes: 11 additions & 11 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async fn nested_subsystem_receives_shutdown() {
Ok(())
};

let subsystem = |mut subsys: SubsystemHandle| async move {
let subsystem = |subsys: SubsystemHandle| async move {
subsys.start("nested", nested_subsystem);
subsys.on_shutdown_requested().await;
Ok(())
Expand Down Expand Up @@ -209,7 +209,7 @@ async fn nested_subsystem_error_propagates() {

let nested_subsystem = |_subsys: SubsystemHandle| async move { Err(anyhow!("Error!")) };

let subsystem = move |mut subsys: SubsystemHandle| async move {
let subsystem = move |subsys: SubsystemHandle| async move {
subsys.start("nested", nested_subsystem);
subsys.on_shutdown_requested().await;
Ok(())
Expand Down Expand Up @@ -246,7 +246,7 @@ async fn panic_gets_handled_correctly() {
panic!("Error!");
};

let subsystem = move |mut subsys: SubsystemHandle| async move {
let subsystem = move |subsys: SubsystemHandle| async move {
subsys.start("nested", nested_subsystem);
subsys.on_shutdown_requested().await;
Ok(())
Expand Down Expand Up @@ -386,7 +386,7 @@ async fn spawning_task_during_shutdown_causes_task_to_be_cancelled() {
Ok(())
};

let subsystem = move |mut subsys: SubsystemHandle| async move {
let subsystem = move |subsys: SubsystemHandle| async move {
subsys.on_shutdown_requested().await;
sleep(Duration::from_millis(100)).await;
subsys.start("Nested", nested);
Expand Down Expand Up @@ -451,7 +451,7 @@ async fn double_panic_does_not_stop_graceful_shutdown() {
panic!("Subsystem2 panicked!")
};

let subsys1 = move |mut subsys: SubsystemHandle| async move {
let subsys1 = move |subsys: SubsystemHandle| async move {
subsys.start("Subsys2", subsys2);
subsys.start("Subsys3", subsys3);
subsys.on_shutdown_requested().await;
Expand Down Expand Up @@ -539,15 +539,15 @@ async fn partial_shutdown_request_stops_nested_subsystems() {
set_subsys3_finished();
Ok(())
};
let subsys2 = move |mut subsys: SubsystemHandle| async move {
let subsys2 = move |subsys: SubsystemHandle| async move {
set_subsys2_started();
subsys.start("subsys3", subsys3);
subsys.on_shutdown_requested().await;
set_subsys2_finished();
Ok(())
};

let subsys1 = move |mut subsys: SubsystemHandle| async move {
let subsys1 = move |subsys: SubsystemHandle| async move {
set_subsys1_started();
let nested_subsys = subsys.start("subsys2", subsys2);
sleep(Duration::from_millis(200)).await;
Expand Down Expand Up @@ -600,7 +600,7 @@ async fn partial_shutdown_panic_gets_propagated_correctly() {
panic!("Nested panicked.");
};

let subsys1 = move |mut subsys: SubsystemHandle| async move {
let subsys1 = move |subsys: SubsystemHandle| async move {
let handle = subsys.start("nested", nested_subsys);
sleep(Duration::from_millis(100)).await;
let result = subsys.perform_partial_shutdown(handle).await;
Expand Down Expand Up @@ -636,7 +636,7 @@ async fn partial_shutdown_error_gets_propagated_correctly() {
Err(anyhow!("nested failed."))
};

let subsys1 = move |mut subsys: SubsystemHandle| async move {
let subsys1 = move |subsys: SubsystemHandle| async move {
let handle = subsys.start("nested", nested_subsys);
sleep(Duration::from_millis(100)).await;
let result = subsys.perform_partial_shutdown(handle).await;
Expand Down Expand Up @@ -672,7 +672,7 @@ async fn partial_shutdown_during_program_shutdown_causes_error() {
Ok(())
};

let subsys1 = move |mut subsys: SubsystemHandle| async move {
let subsys1 = move |subsys: SubsystemHandle| async move {
let handle = subsys.start("nested", nested_subsys);
sleep(Duration::from_millis(100)).await;

Expand Down Expand Up @@ -715,7 +715,7 @@ async fn partial_shutdown_on_wrong_parent_causes_error() {
Ok(())
};

let subsys1 = move |mut subsys: SubsystemHandle| async move {
let subsys1 = move |subsys: SubsystemHandle| async move {
let handle = subsys.start("nested", nested_subsys);

sleep(Duration::from_millis(100)).await;
Expand Down

0 comments on commit 7576b0a

Please sign in to comment.