mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Remove usage of block_on inside of async function
This commit is contained in:
parent
cc07b914c1
commit
751adc04c3
1 changed files with 47 additions and 45 deletions
|
@ -123,54 +123,56 @@ impl Lune {
|
||||||
.detach();
|
.detach();
|
||||||
// Run the executor until there are no tasks left,
|
// Run the executor until there are no tasks left,
|
||||||
// taking care to not exit right away for errors
|
// taking care to not exit right away for errors
|
||||||
let (got_code, got_error, exit_code) = smol::block_on(exec.run(async {
|
let (got_code, got_error, exit_code) = exec
|
||||||
let mut task_count = 0;
|
.run(async {
|
||||||
let mut got_error = false;
|
let mut task_count = 0;
|
||||||
let mut got_code = false;
|
let mut got_error = false;
|
||||||
let mut exit_code = 0;
|
let mut got_code = false;
|
||||||
while let Ok(message) = receiver.recv().await {
|
let mut exit_code = 0;
|
||||||
// Make sure our task-count-modifying messages are sent correctly, one
|
while let Ok(message) = receiver.recv().await {
|
||||||
// task spawned must always correspond to one task finished / errored
|
// Make sure our task-count-modifying messages are sent correctly, one
|
||||||
match &message {
|
// task spawned must always correspond to one task finished / errored
|
||||||
LuneMessage::Exit(_) => {}
|
match &message {
|
||||||
LuneMessage::Spawned => {}
|
LuneMessage::Exit(_) => {}
|
||||||
message => {
|
LuneMessage::Spawned => {}
|
||||||
if task_count == 0 {
|
message => {
|
||||||
bail!(
|
if task_count == 0 {
|
||||||
"Got message while task count was 0!\nMessage: {:#?}",
|
bail!(
|
||||||
message
|
"Got message while task count was 0!\nMessage: {:#?}",
|
||||||
)
|
message
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Handle whatever message we got
|
||||||
|
match message {
|
||||||
|
LuneMessage::Exit(code) => {
|
||||||
|
exit_code = code;
|
||||||
|
got_code = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
LuneMessage::Spawned => task_count += 1,
|
||||||
|
LuneMessage::Finished => task_count -= 1,
|
||||||
|
LuneMessage::Error(e) => {
|
||||||
|
eprintln!("{}", e);
|
||||||
|
got_error = true;
|
||||||
|
task_count += 1;
|
||||||
|
}
|
||||||
|
LuneMessage::LuaError(e) => {
|
||||||
|
eprintln!("{}", pretty_format_luau_error(&e));
|
||||||
|
got_error = true;
|
||||||
|
task_count += 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// If there are no tasks left running, it is now
|
||||||
|
// safe to close the receiver and end execution
|
||||||
|
if task_count == 0 {
|
||||||
|
receiver.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Handle whatever message we got
|
Ok((got_code, got_error, exit_code))
|
||||||
match message {
|
})
|
||||||
LuneMessage::Exit(code) => {
|
.await?;
|
||||||
exit_code = code;
|
|
||||||
got_code = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
LuneMessage::Spawned => task_count += 1,
|
|
||||||
LuneMessage::Finished => task_count -= 1,
|
|
||||||
LuneMessage::Error(e) => {
|
|
||||||
eprintln!("{}", e);
|
|
||||||
got_error = true;
|
|
||||||
task_count += 1;
|
|
||||||
}
|
|
||||||
LuneMessage::LuaError(e) => {
|
|
||||||
eprintln!("{}", pretty_format_luau_error(&e));
|
|
||||||
got_error = true;
|
|
||||||
task_count += 1;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// If there are no tasks left running, it is now
|
|
||||||
// safe to close the receiver and end execution
|
|
||||||
if task_count == 0 {
|
|
||||||
receiver.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok((got_code, got_error, exit_code))
|
|
||||||
}))?;
|
|
||||||
// If we got an error, we will default to exiting
|
// If we got an error, we will default to exiting
|
||||||
// with code 1, unless a code was manually given
|
// with code 1, unless a code was manually given
|
||||||
if got_code {
|
if got_code {
|
||||||
|
|
Loading…
Reference in a new issue