I have two request handlers, one of which waits around looking to see if the other one was called (or eventually times out).
I tried something like this but it doesn't work for some reason:
__gshared bool open_cmd = false;
void command(HttpServerRequest req, HttpServerResponse res)
{
open_cmd = true;
}
void wait(HttpServerRequest req, HttpServerResponse res)
{
StopWatch sw;
sw.start();
while(!open_cmd)
{
Thread.sleep(dur!"msec"(25));
if(sw.peek().seconds > 15)
{
res.writeBody("Timed out", "text/plain");
return;
}
}
open_cmd = false;
res.writeBody("Recieved command", "text/plain");
}
I saw the `Signal
class that says it's for communication between fibers but I don't see a way of having the
wait()
` timeout.
What's a good way to go about doing something like this?