Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: rustfmt.toml #138

Merged
merged 2 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions examples/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,29 @@ const SERVER_URI: &str = "http://localhost:9933";

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
env_logger::init();

let (server_started_tx, server_started_rx) = oneshot::channel::<()>();
let _server = task::spawn(async move {
run_server(server_started_tx, SOCK_ADDR).await;
});
let (server_started_tx, server_started_rx) = oneshot::channel::<()>();
let _server = task::spawn(async move {
run_server(server_started_tx, SOCK_ADDR).await;
});

server_started_rx.await?;
server_started_rx.await?;

let client = HttpClient::new(SERVER_URI);
let response: Result<JsonValue, _> = client.request("say_hello", Params::None).await;
println!("r: {:?}", response);
let client = HttpClient::new(SERVER_URI);
let response: Result<JsonValue, _> = client.request("say_hello", Params::None).await;
println!("r: {:?}", response);

Ok(())
Ok(())
}

async fn run_server(server_started_tx: Sender<()>, url: &str) {
let server = HttpServer::new(url).await.unwrap();
let mut say_hello = server.register_method("say_hello".to_string()).unwrap();

server_started_tx.send(()).unwrap();
loop {
let r = say_hello.next().await;
r.respond(Ok(JsonValue::String("lo".to_owned()))).await;
}
let server = HttpServer::new(url).await.unwrap();
let mut say_hello = server.register_method("say_hello".to_string()).unwrap();

server_started_tx.send(()).unwrap();
loop {
let r = say_hello.next().await;
r.respond(Ok(JsonValue::String("lo".to_owned()))).await;
}
}
55 changes: 24 additions & 31 deletions examples/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,36 @@ const NUM_SUBSCRIPTION_RESPONSES: usize = 10;

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
env_logger::init();

let (server_started_tx, server_started_rx) = oneshot::channel::<()>();
let _server = task::spawn(async move {
run_server(server_started_tx, SOCK_ADDR).await;
});
let (server_started_tx, server_started_rx) = oneshot::channel::<()>();
let _server = task::spawn(async move {
run_server(server_started_tx, SOCK_ADDR).await;
});

server_started_rx.await?;
let client = WsClient::new(SERVER_URI).await?;
let mut subscribe_hello: WsSubscription<JsonValue> = client
.subscribe("subscribe_hello", Params::None, "unsubscribe_hello")
.await?;
server_started_rx.await?;
let client = WsClient::new(SERVER_URI).await?;
let mut subscribe_hello: WsSubscription<JsonValue> =
client.subscribe("subscribe_hello", Params::None, "unsubscribe_hello").await?;

let mut i = 0;
while i <= NUM_SUBSCRIPTION_RESPONSES {
let r = subscribe_hello.next().await;
log::debug!("received {:?}", r);
i += 1;
}
let mut i = 0;
while i <= NUM_SUBSCRIPTION_RESPONSES {
let r = subscribe_hello.next().await;
log::debug!("received {:?}", r);
i += 1;
}

Ok(())
Ok(())
}

async fn run_server(server_started_tx: Sender<()>, url: &str) {
let server = WsServer::new(url).await.unwrap();
let mut subscription = server
.register_subscription(
"subscribe_hello".to_string(),
"unsubscribe_hello".to_string(),
)
.unwrap();
let server = WsServer::new(url).await.unwrap();
let mut subscription =
server.register_subscription("subscribe_hello".to_string(), "unsubscribe_hello".to_string()).unwrap();

server_started_tx.send(()).unwrap();
loop {
subscription
.send(JsonValue::String("hello my friend".to_owned()))
.await;
std::thread::sleep(std::time::Duration::from_secs(1));
}
server_started_tx.send(()).unwrap();
loop {
subscription.send(JsonValue::String("hello my friend".to_owned())).await;
std::thread::sleep(std::time::Duration::from_secs(1));
}
}
36 changes: 18 additions & 18 deletions examples/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ const SERVER_URI: &str = "ws://localhost:9944";

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
env_logger::init();

let (server_started_tx, server_started_rx) = oneshot::channel::<()>();
let _server = task::spawn(async move {
run_server(server_started_tx, SOCK_ADDR).await;
});
let (server_started_tx, server_started_rx) = oneshot::channel::<()>();
let _server = task::spawn(async move {
run_server(server_started_tx, SOCK_ADDR).await;
});

server_started_rx.await?;
let client = WsClient::new(SERVER_URI).await?;
let response: JsonValue = client.request("say_hello", Params::None).await?;
println!("r: {:?}", response);
server_started_rx.await?;
let client = WsClient::new(SERVER_URI).await?;
let response: JsonValue = client.request("say_hello", Params::None).await?;
println!("r: {:?}", response);

Ok(())
Ok(())
}

async fn run_server(server_started_tx: Sender<()>, url: &str) {
let server = WsServer::new(url).await.unwrap();
let mut say_hello = server.register_method("say_hello".to_string()).unwrap();

server_started_tx.send(()).unwrap();
loop {
let r = say_hello.next().await;
r.respond(Ok(JsonValue::String("lo".to_owned()))).await;
}
let server = WsServer::new(url).await.unwrap();
let mut say_hello = server.register_method("say_hello".to_string()).unwrap();

server_started_tx.send(()).unwrap();
loop {
let r = say_hello.next().await;
r.respond(Ok(JsonValue::String("lo".to_owned()))).await;
}
}
Loading