Move await outside of a closure, remove future_wrap dependency
This commit is contained in:
parent
172e276411
commit
2b0b341415
4 changed files with 10 additions and 33 deletions
|
@ -9,31 +9,18 @@ use plugin_runtime::{Plugin, PluginBuilder, WasiFn};
|
|||
use std::{any::Any, path::PathBuf, sync::Arc};
|
||||
use util::ResultExt;
|
||||
|
||||
use future_wrap::*;
|
||||
|
||||
pub async fn new_json(executor: Arc<Background>) -> Result<PluginLspAdapter> {
|
||||
let plugin = PluginBuilder::new_with_default_ctx()?
|
||||
.host_function_async("command", |command: String| async move {
|
||||
dbg!(&command);
|
||||
|
||||
// TODO: actual thing
|
||||
let mut args = command.split(' ');
|
||||
let command = args.next().unwrap();
|
||||
|
||||
dbg!("Running external command");
|
||||
|
||||
let start = std::time::Instant::now();
|
||||
let future = smol::process::Command::new(command).args(args).output();
|
||||
let future = future.wrap(|fut, cx| {
|
||||
dbg!("Poll command!");
|
||||
|
||||
let res = fut.poll(cx);
|
||||
res
|
||||
});
|
||||
let future = future.await;
|
||||
dbg!(start.elapsed());
|
||||
|
||||
future.log_err().map(|output| output.stdout)
|
||||
smol::process::Command::new(command)
|
||||
.args(args)
|
||||
.output()
|
||||
.await
|
||||
.log_err()
|
||||
.map(|output| output.stdout)
|
||||
})?
|
||||
.init(include_bytes!("../../../../plugins/bin/json_language.wasm"))
|
||||
.await?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue