use stdweb::{unstable::TryInto, Reference};
pub fn initialize() -> Option<&'static Reference> {
static mut CHILD_PROCESS: Option<Reference> = None;
if unsafe { CHILD_PROCESS == None } {
unsafe {
CHILD_PROCESS = js! {
return @{ super::js_private() }.child_process = require("child_process");
}.into_reference()
};
}
unsafe { CHILD_PROCESS.as_ref() }
}
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(instance_of = "RUST_NODEJS_PRIVATE.child_process.ChildProcess")]
pub struct ChildProcess(Reference);
impl ChildProcess {
pub fn pid(&self) -> i32 {
(js! {
return @{&self}.pid;
}).try_into()
.expect("PID not number!")
}
}