From 9b58770070b4cdcc47f3a415251c3d58d8e271e3 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Mon, 20 Mar 2023 09:43:48 -0400 Subject: [PATCH] Set up the core run loop --- kifu/kifu-core/src/api.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kifu/kifu-core/src/api.rs b/kifu/kifu-core/src/api.rs index eed51e2..31b3640 100644 --- a/kifu/kifu-core/src/api.rs +++ b/kifu/kifu-core/src/api.rs @@ -11,11 +11,12 @@ pub enum Request { PlayingField, } +#[derive(Debug)] pub enum Response { PlayingFieldView(PlayingFieldView), } -fn disptach(state: Arc>, request: Request) -> Response { +fn dispatch(state: Arc>, request: Request) -> Response { match request { Request::PlayingField => Response::PlayingFieldView(playing_field()), } @@ -45,8 +46,11 @@ impl CoreApp { ) } - pub async fn run(&self) { - thread::sleep(Duration::from_secs(5)); - unimplemented!() + pub async fn run(&mut self) { + loop { + let msg = self.request_rx.recv().await.unwrap(); + let resp = dispatch(self.state.clone(), msg); + self.response_tx.send(resp).await.unwrap(); + } } }