I wrote a vibe.d
web-UI for clang-format
, when presented with this input while using LLVM style, the server hangs.
The code for handling POST:
void post(string style, string code)
{
import std.algorithm;
import std.file;
import std.conv;
import std.process;
auto pipes = pipeProcess(["clang-format", "-style="~style], Redirect.stdout | Redirect.stdin);
scope(exit) wait(pipes.pid);
pipes.stdin.write(code);
pipes.stdin.close;
pipes.pid.wait;
code = pipes.stdout.byLine.joiner.to!string;
string selectedStyle = style;
render!("index.dt", styles, code, selectedStyle);
}
This probably shouldn't be done in a blocking way, but I am at a loss how to do it asynchronously. I have tried wrapping the contents of the function in runTask
, but I couldn't figure out a way to call it correctly.
How can I make it reliable?