demoservices.rs 965 B

12345678910111213141516171819202122232425262728293031323334353637
  1. use async_executor::Executor;
  2. use easy_parallel::Parallel;
  3. use std::sync::Arc;
  4. use drk::Result;
  5. use drk::service::GatewayService;
  6. async fn start(executor: Arc<Executor<'_>>) -> Result<()> {
  7. let gateway = GatewayService::new(
  8. String::from("tcp://127.0.0.1:3333"),
  9. String::from("tcp://127.0.0.1:4444"),
  10. );
  11. gateway.start(executor.clone()).await?;
  12. Ok(())
  13. }
  14. fn main() -> Result<()> {
  15. let ex = Arc::new(Executor::new());
  16. let (signal, shutdown) = async_channel::unbounded::<()>();
  17. let ex2 = ex.clone();
  18. let (_, result) = Parallel::new()
  19. // Run four executor threads.
  20. .each(0..3, |_| smol::future::block_on(ex.run(shutdown.recv())))
  21. // Run the main future on the current thread.
  22. .finish(|| {
  23. smol::future::block_on(async move {
  24. start(ex2).await?;
  25. drop(signal);
  26. Ok::<(), drk::Error>(())
  27. })
  28. });
  29. result
  30. }