mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 04:09:05 +00:00
fix: errors in other modules are ignored
This commit is contained in:
parent
7ba874a85c
commit
eaeb659a7d
13 changed files with 214 additions and 75 deletions
|
@ -1,22 +1,44 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::thread::JoinHandle;
|
||||
use std::thread::{current, JoinHandle, ThreadId};
|
||||
|
||||
use erg_common::dict::Dict;
|
||||
use erg_common::shared::Shared;
|
||||
|
||||
use crate::artifact::ErrorArtifact;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Promise {
|
||||
Running(JoinHandle<Result<(), ErrorArtifact>>),
|
||||
Running {
|
||||
parent: ThreadId,
|
||||
handle: JoinHandle<()>,
|
||||
},
|
||||
Finished,
|
||||
}
|
||||
|
||||
impl Promise {
|
||||
pub fn running(handle: JoinHandle<()>) -> Self {
|
||||
Self::Running {
|
||||
parent: current().id(),
|
||||
handle,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_finished(&self) -> bool {
|
||||
match self {
|
||||
Self::Finished => true,
|
||||
Self::Running(handle) => handle.is_finished(),
|
||||
Self::Running { handle, .. } => handle.is_finished(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn thread_id(&self) -> Option<ThreadId> {
|
||||
match self {
|
||||
Self::Finished => None,
|
||||
Self::Running { handle, .. } => Some(handle.thread().id()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parent_thread_id(&self) -> Option<ThreadId> {
|
||||
match self {
|
||||
Self::Finished => None,
|
||||
Self::Running { parent, .. } => Some(*parent),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,24 +55,52 @@ impl SharedPromises {
|
|||
Self::default()
|
||||
}
|
||||
|
||||
pub fn insert(&self, path: PathBuf, handle: JoinHandle<Result<(), ErrorArtifact>>) {
|
||||
self.0.borrow_mut().insert(path, Promise::Running(handle));
|
||||
pub fn insert(&self, path: PathBuf, handle: JoinHandle<()>) {
|
||||
self.0.borrow_mut().insert(path, Promise::running(handle));
|
||||
}
|
||||
|
||||
pub fn is_registered(&self, path: &Path) -> bool {
|
||||
self.0.borrow_mut().get(path).is_some()
|
||||
self.0.borrow().get(path).is_some()
|
||||
}
|
||||
|
||||
pub fn is_finished(&self, path: &Path) -> bool {
|
||||
self.0
|
||||
.borrow_mut()
|
||||
.borrow()
|
||||
.get(path)
|
||||
.is_some_and(|promise| promise.is_finished())
|
||||
}
|
||||
|
||||
pub fn join(&self, path: &Path) -> Result<(), ErrorArtifact> {
|
||||
pub fn join(&self, path: &Path) -> std::thread::Result<()> {
|
||||
let promise = self.0.borrow_mut().get_mut(path).unwrap().take();
|
||||
let Promise::Running(handle) = promise else { todo!() };
|
||||
handle.join().unwrap()
|
||||
let Promise::Running{ handle, .. } = promise else { todo!() };
|
||||
handle.join()
|
||||
}
|
||||
|
||||
pub fn join_children(&self) {
|
||||
let cur_id = std::thread::current().id();
|
||||
let mut handles = vec![];
|
||||
for (_path, promise) in self.0.borrow_mut().iter_mut() {
|
||||
if promise.parent_thread_id() != Some(cur_id) {
|
||||
continue;
|
||||
}
|
||||
if let Promise::Running { handle, .. } = promise.take() {
|
||||
handles.push(handle);
|
||||
}
|
||||
}
|
||||
for handle in handles {
|
||||
let _result = handle.join();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn join_all(&self) {
|
||||
let mut handles = vec![];
|
||||
for (_path, promise) in self.0.borrow_mut().iter_mut() {
|
||||
if let Promise::Running { handle, .. } = promise.take() {
|
||||
handles.push(handle);
|
||||
}
|
||||
}
|
||||
for handle in handles {
|
||||
let _result = handle.join();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue