1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00
This commit is contained in:
Rob Ede
2022-02-18 02:44:02 +00:00
parent aca1dab890
commit fbd3b228e9
48 changed files with 103 additions and 261 deletions

View File

@ -18,10 +18,7 @@ use serde_json::Value;
mod convention;
/// The main handler for JSONRPC server.
async fn rpc_handler(
body: Bytes,
app_state: web::Data<AppState>,
) -> Result<HttpResponse, Error> {
async fn rpc_handler(body: Bytes, app_state: web::Data<AppState>) -> Result<HttpResponse, Error> {
let reqjson: convention::Request = match serde_json::from_slice(body.as_ref()) {
Ok(ok) => ok,
Err(_) => {
@ -90,10 +87,7 @@ async fn rpc_select(
pub trait ImplNetwork {
fn ping(&self) -> String;
fn wait(
&self,
d: u64,
) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn error::Error>>>>>;
fn wait(&self, d: u64) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn error::Error>>>>>;
fn get(&self) -> u32;
fn inc(&mut self);
@ -114,10 +108,7 @@ impl ImplNetwork for ObjNetwork {
String::from("pong")
}
fn wait(
&self,
d: u64,
) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn error::Error>>>>> {
fn wait(&self, d: u64) -> Pin<Box<dyn Future<Output = Result<String, Box<dyn error::Error>>>>> {
async move {
actix_web::rt::time::sleep(Duration::from_secs(d)).await;
Ok(String::from("pong"))