mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Minor runner improvements
This commit is contained in:
parent
19829d7cf4
commit
5839a7b021
1 changed files with 27 additions and 25 deletions
|
@ -1,4 +1,10 @@
|
||||||
use std::{collections::HashSet, sync::Arc};
|
use std::{
|
||||||
|
collections::HashSet,
|
||||||
|
sync::{
|
||||||
|
atomic::{AtomicU32, Ordering},
|
||||||
|
Arc,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{anyhow, bail, Result};
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
|
@ -9,9 +15,12 @@ pub mod utils;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
globals::{create_console, create_fs, create_net, create_process, create_task},
|
globals::{create_console, create_fs, create_net, create_process, create_task},
|
||||||
utils::formatting::{format_label, pretty_format_luau_error},
|
utils::formatting::pretty_format_luau_error,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
|
use crate::utils::formatting::format_label;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum LuneGlobal {
|
pub enum LuneGlobal {
|
||||||
Console,
|
Console,
|
||||||
|
@ -101,42 +110,35 @@ impl Lune {
|
||||||
.await;
|
.await;
|
||||||
let message = match result {
|
let message = match result {
|
||||||
Ok(_) => LuneMessage::Finished,
|
Ok(_) => LuneMessage::Finished,
|
||||||
Err(e) => LuneMessage::Error(if cfg!(test) {
|
#[cfg(test)]
|
||||||
anyhow!("{}", pretty_format_luau_error(&e))
|
Err(e) => LuneMessage::Error(anyhow!("{}", pretty_format_luau_error(&e))),
|
||||||
} else {
|
#[cfg(not(test))]
|
||||||
anyhow!(
|
Err(e) => LuneMessage::Error(anyhow!(
|
||||||
"\n{}\n{}",
|
"\n{}\n{}",
|
||||||
format_label("ERROR"),
|
format_label("ERROR"),
|
||||||
pretty_format_luau_error(&e)
|
pretty_format_luau_error(&e)
|
||||||
)
|
)),
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
sender.send(message).await
|
sender.send(message).await
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
// Run the executor until there are no tasks left
|
// Run the executor until there are no tasks left
|
||||||
let mut task_count = 1;
|
let task_count = AtomicU32::new(0);
|
||||||
smol::block_on(exec.run(async {
|
smol::block_on(exec.run(async {
|
||||||
while let Ok(message) = receiver.recv().await {
|
while let Ok(message) = receiver.recv().await {
|
||||||
match message {
|
let value = match message {
|
||||||
LuneMessage::Spawned => {
|
LuneMessage::Spawned => task_count.fetch_add(1, Ordering::Relaxed),
|
||||||
task_count += 1;
|
LuneMessage::Finished => task_count.fetch_sub(1, Ordering::Relaxed),
|
||||||
}
|
|
||||||
LuneMessage::Finished => {
|
|
||||||
task_count -= 1;
|
|
||||||
if task_count <= 0 {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LuneMessage::Error(e) => {
|
LuneMessage::Error(e) => {
|
||||||
task_count -= 1;
|
task_count.fetch_sub(1, Ordering::Relaxed);
|
||||||
bail!("{}", e)
|
bail!("{}", e)
|
||||||
}
|
}
|
||||||
LuneMessage::LuaError(e) => {
|
LuneMessage::LuaError(e) => {
|
||||||
task_count -= 1;
|
task_count.fetch_sub(1, Ordering::Relaxed);
|
||||||
bail!("{}", e)
|
bail!("{}", e)
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
println!("Running tasks: {value}");
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}))
|
}))
|
||||||
|
|
Loading…
Reference in a new issue