Skip to content

Commit

Permalink
Add websocket server child spec method.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtzxporter committed Nov 26, 2024
1 parent 4cdf19f commit 77170b4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

### Fixed

# 0.1.33

### Added
- Added `WebsocketServer::child_spec()` to make it easier to supervise the server.

# 0.1.32

### Changed
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ tracing = { version = "0.1", default-features = false, features = ["std"] }
tracing-subscriber = "0.3"
dashmap = "6.0.1"

hydra-macros = { version = "0.1.32", path = "./hydra-macros" }
hydra = { version = "0.1.32", path = "./hydra", default-features = false }
hydra-macros = { version = "0.1.33", path = "./hydra-macros" }
hydra = { version = "0.1.33", path = "./hydra", default-features = false }

[profile.release]
lto = "fat"
Expand Down
2 changes: 1 addition & 1 deletion hydra-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hydra-macros"
version = "0.1.32"
version = "0.1.33"
edition = "2021"
license.workspace = true
repository.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion hydra-websockets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hydra-websockets"
version = "0.1.32"
version = "0.1.33"
edition = "2021"
readme = "./README.md"
license.workspace = true
Expand Down
20 changes: 20 additions & 0 deletions hydra-websockets/src/websocket_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ use tungstenite::protocol::WebSocketConfig;
#[cfg(feature = "native-tls")]
use tokio_native_tls::TlsAcceptor;

use hydra::ChildSpec;
use hydra::ExitReason;
use hydra::GenServer;
use hydra::GenServerOptions;
use hydra::Pid;
use hydra::Process;
use hydra::ProcessFlags;
Expand Down Expand Up @@ -52,6 +54,24 @@ where
}
}

impl<T> WebsocketServer<T>
where
T: WebsocketHandler + Send + Sync + 'static,
{
pub fn child_spec(self) -> ChildSpec {
ChildSpec::new("WebsocketServer").start(move || {
WebsocketServer::start_link(
WebsocketServer {
config: self.config.clone(),
server: None,
_handler: PhantomData::<T>,
},
GenServerOptions::new(),
)
})
}
}

impl<T> GenServer for WebsocketServer<T>
where
T: WebsocketHandler + Send + 'static,
Expand Down
2 changes: 1 addition & 1 deletion hydra/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hydra"
version = "0.1.32"
version = "0.1.33"
edition = "2021"
readme.workspace = true
license.workspace = true
Expand Down

0 comments on commit 77170b4

Please sign in to comment.