Skip to content

Commit

Permalink
windows fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jstuczyn committed Jan 10, 2025
1 parent 606542c commit 4533788
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions common/task/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license.workspace = true
repository.workspace = true

[dependencies]
cfg-if = { workspace = true }
futures = { workspace = true }
log = { workspace = true }
thiserror = { workspace = true }
Expand Down
28 changes: 18 additions & 10 deletions common/task/src/cancellation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2025 - Nym Technologies SA <[email protected]>
// SPDX-License-Identifier: Apache-2.0

use crate::{TaskClient, TaskManager};
use futures::stream::FuturesUnordered;
use futures::StreamExt;
use std::future::Future;
Expand All @@ -13,8 +14,7 @@ use tokio_util::sync::{CancellationToken, DropGuard};
use tokio_util::task::TaskTracker;
use tracing::{debug, info, trace};

use crate::{TaskClient, TaskManager};
#[cfg(not(target_arch = "wasm32"))]
#[cfg(unix)]
use tokio::signal::unix::{signal, SignalKind};

pub const DEFAULT_MAX_SHUTDOWN_DURATION: Duration = Duration::from_secs(5);
Expand Down Expand Up @@ -239,9 +239,15 @@ impl ShutdownManager {

#[cfg(not(target_arch = "wasm32"))]
pub fn with_default_shutdown_signals(self) -> std::io::Result<Self> {
self.with_interrupt_signal()?
.with_terminate_signal()?
.with_quit_signal()
cfg_if::cfg_if! {
if #[cfg(unix)] {
self.with_interrupt_signal()
.with_terminate_signal()?
.with_quit_signal()
} else {
Ok(self.with_interrupt_signal())
}
}
}

#[must_use]
Expand All @@ -260,7 +266,7 @@ impl ShutdownManager {
self
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(unix)]
pub fn with_shutdown_signal(self, signal_kind: SignalKind) -> std::io::Result<Self> {
let mut sig = signal(signal_kind)?;
Ok(self.with_shutdown(async move {
Expand All @@ -269,16 +275,18 @@ impl ShutdownManager {
}

#[cfg(not(target_arch = "wasm32"))]
pub fn with_interrupt_signal(self) -> std::io::Result<Self> {
self.with_shutdown_signal(SignalKind::interrupt())
pub fn with_interrupt_signal(self) -> Self {
self.with_shutdown(async move {
let _ = tokio::signal::ctrl_c().await;
})
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(unix)]
pub fn with_terminate_signal(self) -> std::io::Result<Self> {
self.with_shutdown_signal(SignalKind::terminate())
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(unix)]
pub fn with_quit_signal(self) -> std::io::Result<Self> {
self.with_shutdown_signal(SignalKind::quit())
}
Expand Down

0 comments on commit 4533788

Please sign in to comment.