WIP: support cyclic modules

This commit is contained in:
Shunsuke Shibayama 2023-06-28 00:38:41 +09:00
parent f43b683eda
commit 3e137da0a1
12 changed files with 204 additions and 21 deletions

View file

@ -1,3 +1,4 @@
use std::fmt;
use std::path::{Path, PathBuf};
use std::thread::{current, JoinHandle, ThreadId};
@ -13,6 +14,17 @@ pub enum Promise {
Finished,
}
impl fmt::Display for Promise {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Running { handle, .. } => {
write!(f, "running on thread {:?}", handle.thread().id())
}
Self::Finished => write!(f, "finished"),
}
}
}
impl Promise {
pub fn running(handle: JoinHandle<()>) -> Self {
Self::Running {
@ -50,6 +62,16 @@ impl Promise {
#[derive(Debug, Clone, Default)]
pub struct SharedPromises(Shared<Dict<PathBuf, Promise>>);
impl fmt::Display for SharedPromises {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "SharedPromises {{ ")?;
for (path, promise) in self.0.borrow().iter() {
writeln!(f, "{}: {}, ", path.display(), promise)?;
}
write!(f, "}}")
}
}
impl SharedPromises {
pub fn new() -> Self {
Self::default()