use std::future::Future;
use std::io;
use std::net::SocketAddr;
use crate::server::error::GmfError;
pub trait Runtime: Sized + 'static {
type TcpListener: RuntimeTcpListener;
type Executor: RuntimeExecutor + Clone;
type Semaphore: RuntimeSemaphore;
fn run_multi_core<F, Fut>(cores: usize, f: F) -> Result<(), GmfError>
where
F: Fn(usize) -> Fut + Send + Clone + 'static,
Fut: Future<Output = Result<(), GmfError>> + 'static;
}
pub trait RuntimeTcpListener: Sized {
type Stream: RuntimeTcpStream;
fn bind(addr: SocketAddr) -> impl Future<Output = io::Result<Self>>;
fn accept(&self) -> impl Future<Output = io::Result<(Self::Stream, SocketAddr)>>;
}
pub trait RuntimeTcpStream: Sized + 'static {
type HyperIo: hyper::rt::Read + hyper::rt::Write + Unpin + 'static;
fn into_hyper_io(self) -> Self::HyperIo;
}
pub trait RuntimeExecutor: Clone + Default + 'static {
fn spawn<F: Future<Output = ()> + 'static>(&self, fut: F);
}
pub trait RuntimeSemaphore: Sized {
fn new(permits: usize) -> Self;
fn try_acquire(&self) -> bool;
}