-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question about performing blocking tasks in request handlers #257
Comments
Blocking calls will generally make the event loop dysfunctional, so those need to be replaced or put into a separate thread. Because asynchronous file I/O is currently not implemented for the libevent driver, I have written a thread based wrapper for |
@s-ludwig Wow, thanks so much. I had tried something similar but I'm new to D so I got bogged down in unfamiliarity. One thing I ran into is that I can't see a way to stop Changing the return type of the pre-write callback would break existing code, so maybe the callback can throw a special exception or something to stop the fileserver from sending the contents of the file. That seems hackish though and uses exceptions for non-exceptional situations. Alternatively, the current I don't know how complicated and general-purpose you want |
I would use the
The file server could be extended here, but I want to keep it as simple as possible and not introduce features that can be achieved (equally well) in other ways. Using the |
Alright thanks again, and again great work on vibe, it's such an amazing library. |
In an HTTP request handler, is it ok to make calls to synchronous IO facilities provided by the system? I know vibe does async IO, but I don't know whether it somehow uses libevent to hook all the calls to blocking system IO functions to preempt the tasks or something. I am inexperienced in this field so I don't know what's possible.
The reason I ask is that I need to spawn a process and wait for the output of that process (on a pipe) in creating the response for the HTTP request. I tried making a new thread using
std.concurrency.spawn
and calling vibe'syield
between calls toreceiveTimeout
with a timeout of 1 millisecond, but I get segmentation faults. Even if it had worked, that's a really suboptimal way to do it, I'd rather do it by notifications than polling. What is the best way to do something like this?I think the solution is to just use named pipes and treat them as files. Will reopen if this isn't adequate.
EDIT: Nope, tried that too, threadedfile doesn't like reading named pipes, I get the same error as in #256 . Reopening.
The text was updated successfully, but these errors were encountered: