Files
pages/theseus/src/state/children.rs
Wyatt Verchere f48959a816 Profile bindings (#55)
* basic framework. still has errors

* added functionality for main endpoints + some structuring

* formatting

* unused code

* mimicked CLI function with wait_for process

* made PR changes, added playground

* cargo fmt

* removed missed println

* misc tests fixes

* cargo fmt

* added windows support

* cargo fmt

* all OS use dunce

* restructured profile slightly; fixed mac bug

* profile changes, new main.rs

* fixed requested pr + canonicaliation bug

* fixed regressed bug in ui

* fixed regressed bugs

* fixed git error

* typo

* ran prettier

* clippy

* playground clippy

* ported profile loading fix

* profile change for real, url println and clippy

* PR changes

---------

Co-authored-by: Wyatt <wyatt@modrinth.com>
2023-03-31 11:00:43 -07:00

38 lines
1.0 KiB
Rust

use std::{collections::HashMap, sync::Arc};
use tokio::process::Child;
use tokio::sync::RwLock;
// Child processes (instances of Minecraft)
// A wrapper over a Hashmap connecting PID -> Child
// Left open for future functionality re: polling children
pub struct Children(HashMap<u32, Arc<RwLock<Child>>>);
impl Children {
pub fn new() -> Children {
Children(HashMap::new())
}
// Inserts and returns a ref to the child
// Unlike a Hashmap, this directly returns the reference to the Child rather than any previously stored Child that may exist
pub fn insert(
&mut self,
pid: u32,
child: tokio::process::Child,
) -> Arc<RwLock<Child>> {
let child = Arc::new(RwLock::new(child));
self.0.insert(pid, child.clone());
child
}
// Returns a ref to the child
pub fn get(&self, pid: &u32) -> Option<Arc<RwLock<Child>>> {
self.0.get(pid).cloned()
}
}
impl Default for Children {
fn default() -> Self {
Self::new()
}
}