Skip to content
Snippets Groups Projects
Commit 10f035d1 authored by Stephen D's avatar Stephen D
Browse files

Fix CPU blocking async

parent 8df7f656
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ use std::borrow::Cow; ...@@ -12,6 +12,7 @@ use std::borrow::Cow;
use std::collections::HashMap; use std::collections::HashMap;
use std::str::FromStr; use std::str::FromStr;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use tokio::task;
use xbasic::basic_io::BasicIO; use xbasic::basic_io::BasicIO;
use xbasic::expr::ExprValue; use xbasic::expr::ExprValue;
use xbasic::xbasic::XBasicBuilder; use xbasic::xbasic::XBasicBuilder;
...@@ -204,7 +205,7 @@ impl Handler { ...@@ -204,7 +205,7 @@ impl Handler {
let code = self.programs.lock().unwrap()[&msg.author.id].stringify(); let code = self.programs.lock().unwrap()[&msg.author.id].stringify();
let io = DiscordIO::new(); let io = DiscordIO::new();
let (output, fb, errors) = { let (output, fb, errors) = task::spawn_blocking(move || {
let mut xbb = XBasicBuilder::new(io); let mut xbb = XBasicBuilder::new(io);
xbb.compute_limit(1000000000); xbb.compute_limit(1000000000);
...@@ -247,7 +248,9 @@ impl Handler { ...@@ -247,7 +248,9 @@ impl Handler {
}; };
(xb.get_io().s.clone(), xb.get_io().frame.clone(), errors) (xb.get_io().s.clone(), xb.get_io().frame.clone(), errors)
}; })
.await
.unwrap();
if !output.is_empty() { if !output.is_empty() {
msg.channel_id.say(&ctx, output).await.unwrap(); msg.channel_id.say(&ctx, output).await.unwrap();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment