use std::sync::Arc;

use aok::{OK, Void};
use log::info;
use msgq::{Kv, ReadGroup};

#[static_init::constructor(0)]
extern "C" fn _log_init() {
  log_init::init();
}

async fn on_error(mail: Arc<Kv>, error: String) -> Void {
  info!("on_error {error} {:?}", mail);
  OK
}

async fn print_mail(mail: Arc<Kv>) -> Void {
  info!("print_mail {:?}", mail);
  Err(aok::anyhow!("test error"))
}

#[tokio::test]
async fn test_async() -> Void {
  xboot::init().await?;
  let read_group = ReadGroup::new("smtp", "send", "test", 1, 3, 2);
  read_group.run(print_mail, on_error).await?;
  OK
}
