Skip to main content

ntex_server/
lib.rs

1#![deny(clippy::pedantic)]
2#![allow(
3    clippy::missing_fields_in_debug,
4    clippy::must_use_candidate,
5    clippy::missing_errors_doc
6)]
7
8use ntex_service::ServiceFactory;
9
10mod manager;
11pub mod net;
12mod pool;
13mod server;
14mod signals;
15mod wrk;
16
17pub use self::pool::WorkerPool;
18pub use self::server::Server;
19pub use self::signals::{Signal, signal};
20pub use self::wrk::{Worker, WorkerStatus, WorkerStop};
21
22/// Worker id
23#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
24pub struct WorkerId(pub(crate) usize);
25
26impl WorkerId {
27    pub(self) fn next(&mut self) -> WorkerId {
28        let id = WorkerId(self.0);
29        self.0 += 1;
30        id
31    }
32}
33
34#[allow(async_fn_in_trait)]
35/// Worker service factory.
36pub trait ServerConfiguration: Send + Clone + 'static {
37    type Item: Send + 'static;
38    type Factory: ServiceFactory<Self::Item> + 'static;
39
40    /// Create service factory for handling `WorkerMessage<T>` messages.
41    async fn create(&self) -> Result<Self::Factory, ()>;
42
43    /// Server is paused.
44    fn paused(&self) {}
45
46    /// Server is resumed.
47    fn resumed(&self) {}
48
49    /// Server is stopped
50    fn terminate(&self) {}
51
52    /// Server is stopped
53    async fn stop(&self) {}
54}