Skip to content

Commit

Permalink
merge: resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Sep 26, 2024
2 parents c4e73f4 + d8f688a commit 7238b06
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
10 changes: 4 additions & 6 deletions crates/aionbot-adapter-onebot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ pub mod ws;

use std::sync::Arc;

use aionbot_core::{
event::Event,
runtime::{Runtime, StateManager},
};
use aionbot_core::event::Event;
use aionbot_core::runtime::{Runtime, RuntimeStatus, StateManager};
use anyhow::Result;
use tokio::sync::broadcast::Receiver;
use ws::Onebot;
Expand Down Expand Up @@ -66,8 +64,8 @@ impl Runtime for OnebotRuntime {
Ok(())
}

async fn run(&mut self) -> Result<()> {
async fn run(&mut self) -> Result<RuntimeStatus> {
self.receiver.as_mut().unwrap().recv().await?;
Ok(())
Ok(RuntimeStatus::Exit)
}
}
29 changes: 26 additions & 3 deletions crates/aionbot-core/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,29 @@ where
self
}

pub async fn run(&mut self) -> Result<()> {
async fn prepare(&mut self) -> Result<()> {
self.runtime.prepare().await?;
if let Some(setup) = self.setup.take() {
self.runtime.setup(setup);
}
self.runtime.finalize().await?;
self.runtime.run().await
Ok(())
}

pub async fn run(&mut self) -> Result<()> {
self.prepare().await?;

loop {
match self.runtime.run().await? {
RuntimeStatus::Pending => {}
RuntimeStatus::Exit => break,
RuntimeStatus::Next => {}
RuntimeStatus::Restart => {
self.runtime.prepare().await?;
}
}
}
Ok(())
}
}

Expand Down Expand Up @@ -95,5 +111,12 @@ pub trait Runtime {
async move { Ok(()) }
}

fn run(&mut self) -> impl std::future::Future<Output = Result<()>> + Send;
fn run(&mut self) -> impl std::future::Future<Output = Result<RuntimeStatus>> + Send;
}

pub enum RuntimeStatus {
Pending,
Exit,
Next,
Restart,
}

0 comments on commit 7238b06

Please sign in to comment.