Create trait for status events
This commit is contained in:
Generated
+1
@@ -4646,6 +4646,7 @@ dependencies = [
|
||||
"nym-ecash-contract-common",
|
||||
"nym-ecash-time",
|
||||
"nym-network-defaults",
|
||||
"nym-task",
|
||||
"nym-validator-client",
|
||||
"rand",
|
||||
"thiserror",
|
||||
|
||||
@@ -14,14 +14,15 @@ thiserror = { workspace = true }
|
||||
url = { workspace = true }
|
||||
zeroize = { workspace = true }
|
||||
|
||||
nym-ecash-time = { path = "../ecash-time" }
|
||||
nym-credential-storage = { path = "../credential-storage" }
|
||||
nym-credentials = { path = "../credentials" }
|
||||
nym-credentials-interface = { path = "../credentials-interface" }
|
||||
nym-crypto = { path = "../crypto", features = ["rand", "asymmetric", "stream_cipher", "aes", "hashing"] }
|
||||
nym-network-defaults = { path = "../network-defaults" }
|
||||
nym-validator-client = { path = "../client-libs/validator-client", default-features = false }
|
||||
nym-ecash-contract-common = { path = "../cosmwasm-smart-contracts/ecash-contract" }
|
||||
nym-ecash-time = { path = "../ecash-time" }
|
||||
nym-network-defaults = { path = "../network-defaults" }
|
||||
nym-task = { path = "../task" }
|
||||
nym-validator-client = { path = "../client-libs/validator-client", default-features = false }
|
||||
|
||||
[target."cfg(not(target_arch = \"wasm32\"))".dependencies.nym-validator-client]
|
||||
path = "../client-libs/validator-client"
|
||||
|
||||
@@ -11,3 +11,9 @@ pub enum BandwidthStatusMessage {
|
||||
#[error("no bandwidth left")]
|
||||
NoBandwidth,
|
||||
}
|
||||
|
||||
impl nym_task::manager::TaskEvent for BandwidthStatusMessage {
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,3 +221,9 @@ pub enum ClientCoreStatusMessage {
|
||||
#[error("The connected gateway is very slow, or the connection to it is very slow")]
|
||||
GatewayIsVerySlow,
|
||||
}
|
||||
|
||||
impl nym_task::manager::TaskEvent for ClientCoreStatusMessage {
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,3 +28,9 @@ impl From<ConnectionError> for Socks5ClientCoreError {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl nym_task::manager::TaskEvent for Socks5ClientCoreError {
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
use futures::{future::pending, FutureExt, SinkExt, StreamExt};
|
||||
use log::{log, Level};
|
||||
use std::any::Any;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::{error::Error, time::Duration};
|
||||
use tokio::sync::{
|
||||
@@ -22,7 +23,8 @@ pub(crate) type SentError = Box<dyn Error + Send + Sync>;
|
||||
type ErrorSender = mpsc::UnboundedSender<SentError>;
|
||||
type ErrorReceiver = mpsc::UnboundedReceiver<SentError>;
|
||||
|
||||
pub type SentStatus = Box<dyn Error + Send + Sync>;
|
||||
// pub type SentStatus = Box<dyn Error + Send + Sync>;
|
||||
pub type SentStatus = Box<dyn TaskEvent>;
|
||||
pub type StatusSender = futures::channel::mpsc::Sender<SentStatus>;
|
||||
pub type StatusReceiver = futures::channel::mpsc::Receiver<SentStatus>;
|
||||
|
||||
@@ -40,6 +42,10 @@ enum TaskError {
|
||||
UnexpectedHalt { shutdown_name: Option<String> },
|
||||
}
|
||||
|
||||
pub trait TaskEvent: std::error::Error + Send + Sync + Any {
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
}
|
||||
|
||||
// TODO: possibly we should create a `Status` trait instead of reusing `Error`
|
||||
#[derive(thiserror::Error, Debug, PartialEq, Eq)]
|
||||
pub enum TaskStatus {
|
||||
@@ -49,6 +55,12 @@ pub enum TaskStatus {
|
||||
ReadyWithGateway(String),
|
||||
}
|
||||
|
||||
impl TaskEvent for TaskStatus {
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Listens to status and error messages from tasks, as well as notifying them to gracefully
|
||||
/// shutdown. Keeps track of if task stop unexpectedly, such as in a panic.
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -655,6 +655,7 @@ where
|
||||
.next()
|
||||
.await
|
||||
.ok_or(Error::Socks5NotStarted)?
|
||||
.as_any()
|
||||
.downcast_ref::<TaskStatus>()
|
||||
.ok_or(Error::Socks5NotStarted)?
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user