Skip to content

Commit 1bd00ba

Browse files
committed
Fix example
Fixes #88. Signed-off-by: Joe Grund <joe@thelustrecollective.com>
1 parent 24ea6eb commit 1bd00ba

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

irpc-iroh/examples/remote-and-local.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ use self::storage::StorageApi;
99

1010
#[tokio::main]
1111
async fn main() -> Result<()> {
12+
run().await
13+
}
14+
15+
#[tokio::test]
16+
async fn test() -> Result<()> {
17+
run().await
18+
}
19+
20+
async fn run() -> Result<()> {
1221
tracing_subscriber::fmt::init();
1322
println!("Local use");
1423
local().await?;
@@ -30,18 +39,16 @@ async fn local() -> Result<()> {
3039
}
3140

3241
async fn remote() -> Result<()> {
33-
let (server_router, server_addr) = {
34-
let endpoint = Endpoint::bind().await?;
35-
let api = StorageApi::spawn();
36-
let router = Router::builder(endpoint.clone())
37-
.accept(StorageApi::ALPN, api.protocol_handler()?)
38-
.spawn();
39-
let addr = endpoint.addr();
40-
(router, addr)
41-
};
42+
let endpoint = Endpoint::bind().await?;
43+
let api = StorageApi::spawn();
44+
let router = Router::builder(endpoint.clone())
45+
.accept(StorageApi::ALPN, api.protocol_handler()?)
46+
.spawn();
47+
48+
endpoint.online().await;
4249

4350
let client_endpoint = Endpoint::builder().bind().await?;
44-
let api = StorageApi::connect(client_endpoint, server_addr)?;
51+
let api = StorageApi::connect(client_endpoint, endpoint.addr())?;
4552
api.set("hello".to_string(), "world".to_string()).await?;
4653
api.set("goodbye".to_string(), "world".to_string()).await?;
4754
let value = api.get("hello".to_string()).await?;
@@ -50,7 +57,9 @@ async fn remote() -> Result<()> {
5057
while let Some(value) = list.recv().await? {
5158
println!("list value = {value:?}");
5259
}
53-
drop(server_router);
60+
61+
router.shutdown().await?;
62+
5463
Ok(())
5564
}
5665

0 commit comments

Comments
 (0)