add container to pool

This commit is contained in:
mii443
2024-10-10 09:39:08 +00:00
parent bd7fdbe2da
commit c188b4ecb5
2 changed files with 15 additions and 1 deletions

View File

@ -24,6 +24,7 @@ impl ContainerPool {
false
}
}) {
println!("Using container from pool");
let container = pool[i].clone();
pool.remove(i);
container
@ -31,4 +32,11 @@ impl ContainerPool {
Container::from_language(language).await
}
}
pub async fn add_container(&mut self, language: Language) {
self.containers
.lock()
.await
.push(Container::from_language(language).await);
}
}

View File

@ -50,6 +50,12 @@ async fn main() -> Result<(), ()> {
let intents =
serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT;
let mut pool = ContainerPool::new();
for _ in 0..10 {
pool.add_container(config.get_language(&"Ruby".to_string()).unwrap())
.await;
}
let framework = poise::Framework::builder()
.setup({
let config = config.clone();
@ -57,7 +63,7 @@ async fn main() -> Result<(), ()> {
Box::pin(async move {
Ok(Data {
config: Arc::new(Mutex::new(config)),
container_pool: Arc::new(Mutex::new(ContainerPool::new())),
container_pool: Arc::new(Mutex::new(pool)),
})
})
}