#object #asynchronous #arc-mutex

macro bin async_init

init object asynchronously without Arc<Mutex>

1 unstable release

0.1.0 Jun 11, 2020

#13 in #arc-mutex

MIT license

6KB
72 lines

async_init

init object asynchronously without Arc

#[async_init]
pub async fn get_db_pool() -> Result<MySqlPool, sqlx::Error> {
    println!("thread id is {:?}, create mysql pool", thread::current().id());
    let db_url = env::var("DATABASE_URL").expect("`DATABASE_URL` must be set to run this app");
    let pool:MySqlPool = Pool::new(&db_url).await?;
    Ok(pool)
}

Dependencies

~3.5–4.5MB
~89K SLoC