pub struct Engine { /* private fields */ }Expand description
The Engine is the main struct of the Runtime.
It drives the runtime Accepting Requests Answering them etc.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn new(addr: impl ToSocketAddrs) -> Self
pub fn new(addr: impl ToSocketAddrs) -> Self
Creates a new Engine instance without a config
Sourcepub fn with_config(config: EngineConfig) -> Self
pub fn with_config(config: EngineConfig) -> Self
Creates a new Engine instance with a config
Sourcepub fn spawn(&self, task: impl FnOnce() + Send + 'static)
pub fn spawn(&self, task: impl FnOnce() + Send + 'static)
Add a new task to the internal TaskPool works like thread::spawn but its managed bythe Engine
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Trigger the shutdown flag to stop the Engine. This method will unblock the thread that is waiting for a message. It will also stop the acceptor thread. This method should be called when the Engine is shutting down. Its Called when the Engine is dropped.
Sourcepub fn start(&self)
pub fn start(&self)
Starts Acceptor thread. This thread will accept incoming connections and push them to the queue. The thread will run until the Engine is shutdown.
Sourcepub fn recv(&self) -> IoResult<Request>
pub fn recv(&self) -> IoResult<Request>
Blocks until a message is available to receive. If the queue is empty, it will wait until a message is available. If the queue is unblocked, it will return an error.
Sourcepub fn unblock(&self)
pub fn unblock(&self)
Unblocks the thread that is waiting for a message. this medhod allows graceful shutdown of the Engine’s Runtime.
Sourcepub fn for_each<F>(self, handle: F) -> Result<()>
pub fn for_each<F>(self, handle: F) -> Result<()>
Iterates over incoming requests and handles them using the provided closure.
The closure should take a HttpRequest and return a HttpResponse.
This method will block until a request is available.
It will also handle the response and write it to the stream.