You've already forked AstralRinth
forked from didirus/AstralRinth
fixes stack overflow :) (#88)
* fixes stack overflow :) * removed unnecessary comment
This commit is contained in:
@@ -194,70 +194,53 @@ pub async fn emit_profile(
|
|||||||
// loading_join!(loading_bar, 0.1; task1, task2, task3)
|
// loading_join!(loading_bar, 0.1; task1, task2, task3)
|
||||||
// This will await on each of the tasks, and as each completes, it will emit a loading event for 0.033, 0.066, 0.099, etc
|
// This will await on each of the tasks, and as each completes, it will emit a loading event for 0.033, 0.066, 0.099, etc
|
||||||
// This should function as a drop-in replacement for tokio::try_join_all! in most cases- except the function *itself* calls ? rather than needing it.
|
// This should function as a drop-in replacement for tokio::try_join_all! in most cases- except the function *itself* calls ? rather than needing it.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! count {
|
||||||
|
() => (0usize);
|
||||||
|
( $x:tt $($xs:tt)* ) => (1usize + $crate::count!($($xs)*));
|
||||||
|
}
|
||||||
#[cfg(feature = "tauri")]
|
#[cfg(feature = "tauri")]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! loading_join {
|
macro_rules! loading_join {
|
||||||
($key:expr, $total:expr, $message:expr; $($future:expr $(,)?)+) => {{
|
($key:expr, $total:expr, $message:expr; $($task:expr $(,)?)+) => {
|
||||||
let mut num_futures = 0;
|
{
|
||||||
$(
|
let key = $key;
|
||||||
{
|
let message : Option<&str> = $message;
|
||||||
let _ = &$future; // useless to allow matching to $future
|
|
||||||
num_futures += 1;
|
let num_futures = $crate::count!($($task)*);
|
||||||
}
|
|
||||||
)*
|
|
||||||
let increment = $total / num_futures as f64;
|
let increment = $total / num_futures as f64;
|
||||||
|
|
||||||
// Create tokio::pinned values
|
|
||||||
$(
|
|
||||||
paste::paste! {
|
|
||||||
tokio::pin! {
|
|
||||||
let [<unique_name_ $future>] = $future;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)*
|
|
||||||
$(
|
|
||||||
paste::paste! {
|
|
||||||
let mut [<result_ $future>] = None;
|
|
||||||
}
|
|
||||||
)*
|
|
||||||
|
|
||||||
// Resolve each future and call respective loading as each resolves in any order
|
paste::paste! {
|
||||||
for _ in 0..num_futures {
|
$( let [ <unique_name $task>] = {
|
||||||
paste::paste! {
|
{
|
||||||
tokio::select! {
|
let key = key.clone();
|
||||||
$(
|
let message = message.clone();
|
||||||
v = &mut [<unique_name_ $future>], if ![<result_$future>].is_some() => {
|
async move {
|
||||||
if let Some(key) = $key {
|
let res = $task.await;
|
||||||
$crate::event::emit::emit_loading(key, increment, $message).await?;
|
if let Some(key) = key {
|
||||||
}
|
$crate::event::emit::emit_loading(key, increment, message).await?;
|
||||||
[<result_ $future>] = Some(v);
|
}
|
||||||
},
|
res
|
||||||
)*
|
}
|
||||||
else => break,
|
|
||||||
}
|
}
|
||||||
}
|
};)+
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract values out of option, then out of error, returning if any errors happened
|
paste::paste! {
|
||||||
$(
|
tokio::try_join! (
|
||||||
paste::paste! {
|
$( [ <unique_name $task>] ),+
|
||||||
let [<result_ $future>] = [<result_ $future>].take().unwrap()?; // unwrap here acceptable as numbers of futures and resolved values is guaranteed to be the same
|
)
|
||||||
}
|
|
||||||
)*
|
|
||||||
|
|
||||||
paste::paste!{
|
|
||||||
($(
|
|
||||||
[<result_ $future>], // unwrap here acceptable as numbers of futures and resolved values is guaranteed to be the same
|
|
||||||
)+)
|
|
||||||
}
|
}
|
||||||
}};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "tauri"))]
|
#[cfg(not(feature = "tauri"))]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! loading_join {
|
macro_rules! loading_join {
|
||||||
($start:expr, $end:expr, $message:expr; $($future:expr $(,)?)+) => {{
|
($start:expr, $end:expr, $message:expr; $($future:expr $(,)?)+) => {{
|
||||||
tokio::try_join!($($future),+)?
|
tokio::try_join!($($future),+)
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ impl State {
|
|||||||
let (metadata, profiles) = loading_join! {
|
let (metadata, profiles) = loading_join! {
|
||||||
Some(&loading_bar), 20.0, Some("Initializing metadata and profiles...");
|
Some(&loading_bar), 20.0, Some("Initializing metadata and profiles...");
|
||||||
metadata_fut, profiles_fut
|
metadata_fut, profiles_fut
|
||||||
};
|
}?;
|
||||||
|
|
||||||
emit_loading(&loading_bar, 10.0, None).await?;
|
emit_loading(&loading_bar, 10.0, None).await?;
|
||||||
let users = Users::init(&database)?;
|
let users = Users::init(&database)?;
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ impl Tags {
|
|||||||
licenses_fut,
|
licenses_fut,
|
||||||
donation_platforms_fut,
|
donation_platforms_fut,
|
||||||
report_types_fut
|
report_types_fut
|
||||||
);
|
)?;
|
||||||
|
|
||||||
// Store the tags in the database
|
// Store the tags in the database
|
||||||
self.0.categories.insert(
|
self.0.categories.insert(
|
||||||
|
|||||||
Reference in New Issue
Block a user