Hi,
so my code looks like:
# in the controller:
$self->write_chunk($initial_json_stuff);
...
# In a model, invoked by controller
$controller->write_chunk($some_json);
$self->write_results($query);
# return data to controller
sub write_results {
my $cb;
$cb = sub {
if(my $row = $query->hash) {
my $txt = ... # JSON encode hash
$controller->write_chunk($txt,$cb);
}
$cb->();
}
...
# back in controller
$self->write_chunk($final_json_stuff);
$self->finish();
The problem is that although the $cb anonymous sub is called the correct
number of times, the model's sub routine exits and the controller finishes
the transaction so the outcome is that only 1 record gets written to the
output before the controller completes the transaction.
I can get it to work by having the model write $final_json_stuff
This is extremely annoying as now my model has to know about controller
related stuff (e.g. is this a JSONP request), whereas I'd like the model to
just write out the raw JSON as an array to an output stream that it's been
given and not have to be given extra knowledge about the request or the
controller.
Does anybody else have any ideas on how to write in a blocking,
non-buffering manner to the output stream?
Thanks,
Allan
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.