quannadev of gapo.tinh-te
3/15/2020 - 2:11 PM

Mysql Actor

Mysql Actor

  • Sử dụng Pool Connection Manager
  • SyncContext
use actix::{Actor, SyncContext};
use diesel::{MysqlConnection, r2d2::ConnectionManager};
use r2d2::Pool;

pub struct MysqlActor {
    conn: Pool<ConnectionManager<MysqlConnection>>
}

impl MysqlActor {
    pub fn new(conn: Pool<ConnectionManager<MysqlConnection>>) -> Self {
        MysqlActor { conn }
    }
}

impl Actor for MysqlActor {
    type Context = SyncContext<Self>;

    fn started(&mut self, _ctx: &mut Self::Context) {
        info!("Mysql Actor started")
    }
}