Approach for pushing a series of file operations into non-blocking callback

23 views
Skip to first unread message

Charlie Brady

unread,
Apr 1, 2016, 2:09:55 PM4/1/16
to mojol...@googlegroups.com

I'm starting on the task of converting a preforking server into a
non-blocking server for a small webservice. One of my handlers generates a
data structure by reading the content of a subtree of files.

In essense, it does something like this:

...
my $data = {
map { $_ => Mojo::Util::slurp("/path/to/files/$_" }
(qw(one two three four));
};
$c->render(json => $data);
};

Can someone give me some hints as to how to do that as a series of
non-blocking callbacks, or do we just shrug and say "it's not going to
block for too long".

Thanks

olivier...@gmail.com

unread,
Apr 2, 2016, 12:42:38 PM4/2/16
to Mojolicious, charli...@budge.apana.org.au
I guess it depends how much time does the slurping takes. If you think this request is blocking for too long, then you could read the files inside a fork using Mojo::IOLoop::ForkCall for instance.
Reply all
Reply to author
Forward
0 new messages