Skip to content

Commit caac9db

Browse files
committed
Ditch Arc::try_new() fallible alloc in Engine::new()
If `Arc::new()` causes an OOM error, there is nothing we can do about it except abort the program initialization... which plain `Arc::new()` does anyway, without the boilerplate. We should only use fallible allocation in areas where we can reasonably recover, e.g. dynamically while spawing/modifying containers.
1 parent 3654f2e commit caac9db

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/main.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::sync::Arc;
33
use anyhow::anyhow;
44
use dashmap::DashMap;
55
use fallible_collections::tryformat;
6-
use fallible_collections::FallibleArc;
76

87
use self::container::Container;
98
use self::image::OciImage;
@@ -18,8 +17,8 @@ pub struct Engine {
1817
}
1918

2019
impl Engine {
21-
pub async fn new() -> anyhow::Result<Self> {
22-
let containers = Arc::try_new(DashMap::new()).map_err(|e| anyhow!("OOM error: {:?}", e))?;
20+
pub fn new() -> Self {
21+
let containers = Arc::new(DashMap::new());
2322
let running = containers.clone();
2423

2524
// TODO: Find a way to avoid using `tokio::spawn()` and convert to `join!()` instead.
@@ -30,7 +29,7 @@ impl Engine {
3029
}
3130
});
3231

33-
Ok(Engine { containers })
32+
Engine { containers }
3433
}
3534

3635
pub async fn create(&self, container_name: &str) -> anyhow::Result<()> {
@@ -78,7 +77,7 @@ impl Engine {
7877
#[tokio::main]
7978
async fn main() -> anyhow::Result<()> {
8079
// TODO: Use `warp` to host REST endpoints.
81-
let engine = Engine::new().await?;
80+
let engine = Engine::new();
8281
engine.create("busybox").await?;
8382
tokio::time::sleep(std::time::Duration::from_secs(1000)).await;
8483
Ok(())

0 commit comments

Comments
 (0)