[Mojolicious] Re: write_chunk

2015-06-11 Thread Daniel Mantovani
A few weeks ago I run in a similar problem trying to repetitively run a group of steps for a simple get operation without blocking the controller. After receiving some advices from the #mojo irc channel folks I end up with a plugin that should be able to repeat a set of steps without block the

[Mojolicious] Re: write_chunk

2015-06-11 Thread Allan Cochrane
On Thursday, 11 June 2015 01:33:03 UTC-5, Roger Crew wrote: > > > To my mind the callback runs and as part of its functionality schedules > itself for later execution, it doesn't invoke itself directly as > 'classical' recursion. > > This much is correct, i.e., you're only creating a closure on

[Mojolicious] Re: write_chunk

2015-06-10 Thread Roger Crew
> To my mind the callback runs and as part of its functionality schedules itself for later execution, it doesn't invoke itself directly as 'classical' recursion. This much is correct, i.e., you're only creating a closure once, and all calls to it except for the first are coming from the event l

[Mojolicious] Re: write_chunk

2015-06-10 Thread Allan Cochrane
Hi, On Wednesday, 10 June 2015 17:51:35 UTC-5, Roger Crew wrote: > > > No. What I actually meant was this: > > > # DO NOTHING FURTHER HERE; WE HAVE TO WAIT FOR THE CALLBACKS TO ACTUALLY GET > CALLED > > > that sounds better than what I had written Thanks, Allan -- You received this message

[Mojolicious] Re: write_chunk

2015-06-10 Thread Allan Cochrane
Hi, just nit-picking here but since the callbacks do not actually invoke themselves is it really recursion? To my mind the callback runs and as part of its functionality schedules itself for later execution, it doesn't invoke itself directly as 'classical' recursion. Can anyone explain where

[Mojolicious] Re: write_chunk

2015-06-10 Thread Roger Crew
On Tuesday, June 9, 2015 at 5:46:55 AM UTC-7, Allan Cochrane wrote: > > Hi, > > can I suggest that something akin to Roger's comment: > > # DO NOTHING FURTHER HERE, MAY BE IGNORED BY CLIENT > > No. What I actually meant was this: # DO NOTHING FURTHER HERE; WE HAVE TO WAIT FOR THE CALLBACKS TO

[Mojolicious] Re: write_chunk

2015-06-09 Thread sri
> > Using https://gist.github.com/AllanCochrane/1dd34f0fd3649ece7689 > > > as an example, the callback code *looks *recursive (and you alluded t

[Mojolicious] Re: write_chunk

2015-06-09 Thread Allan Cochrane
In what way does it sound wrong? Where is my misunderstanding? Using https://gist.github.com/AllanCochrane/1dd34f0fd3649ece7689 as an example, the callback code *looks *recursive (and you alluded to that in a comment above) but it actually isn't. My naive interpretation is that the callback imm

[Mojolicious] Re: write_chunk

2015-06-09 Thread sri
> > can I suggest that something akin to Roger's comment: > > # DO NOTHING FURTHER HERE, MAY BE IGNORED BY CLIENT > > > be added to the hello world example in the documentation as it might help > folk understand that all subsequent output must be done in the callback to > appear in the stream in

[Mojolicious] Re: write_chunk

2015-06-09 Thread Allan Cochrane
Hi, can I suggest that something akin to Roger's comment: # DO NOTHING FURTHER HERE, MAY BE IGNORED BY CLIENT be added to the hello world example in the documentation as it might help folk understand that all subsequent output must be done in the callback to appear in the stream in the correc

[Mojolicious] Re: write_chunk

2015-06-09 Thread sri
> > It is annoying not to have a way to just write to the output stream > without resorting to callbacks, in this scenario. > The cost of scalability. If you could perform blocking writes to the output stream, you would only be able to handle one request at a time per worker process, instead o

[Mojolicious] Re: write_chunk

2015-06-08 Thread Roger Crew
> will see if I can restructure the code to use such a construct. It would actually be pretty straightforward, in my code, at least, to encapsulate everything from that first write_chunk call down to the initial $cb->() invocation as a helper function -- it's all pretty generic -- and then that

[Mojolicious] Re: write_chunk

2015-06-08 Thread Allan Cochrane
Hi, I eventually came up with almost the same code except I pushed the writing down to the model whereas you've pulled it up to the controller. I like the idea of a viewer (aka conductor or presenter) and will see if I can restructure the code to use such a construct. Unfortunately my DB drive

[Mojolicious] Re: write_chunk

2015-06-08 Thread Roger Crew
Your problem (if I'm reading your code right) is that you don't have anything to catch when the query has exhausted itself. Instead it looks like you're immediately calling write_chunk($final_json_stuff) after the first callback returns, which then closes the JSON object being constructed, an

[Mojolicious] Re: write_chunk

2015-06-08 Thread Allan Cochrane
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

[Mojolicious] Re: write_chunk

2015-06-05 Thread Allan Cochrane
Ok, but if you _could_ add an example, what would it look like? :-) 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 mojolicious+unsubscr...@googlegroups.c

[Mojolicious] Re: write_chunk

2015-06-05 Thread sri
> > is there a pattern that I should be following in the example above? Can > you point me to example code perhaps? > Actually, i always wanted to add an example to the documentation. But a nice one would be using the __SUB__ feature from Perl 5.16. Sadly the community at large has voted again

[Mojolicious] Re: write_chunk

2015-06-05 Thread Allan Cochrane
Hi, is there a pattern that I should be following in the example above? Can you point me to example code perhaps? 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,

[Mojolicious] Re: write_chunk

2015-06-05 Thread sri
> > As an aside, I don't think I need to actually write in chunks, since > Mojolicious' write() method also takes a callback to cause the output > buffer to flush. > We don't ever flush, that would be a blocking operation. The callback only notifies you that the buffer is empty, so you have to

[Mojolicious] Re: write_chunk

2015-06-05 Thread Allan Cochrane
I should also say that the code really looks like this: # in the controller: $self->write_chunk($initial_json_stuff); ... # In a model, invoked by controller while (my $row = $query->hash) { my $txt = ... # JSON encode hash $controller->write_chunk($txt); $count++; $self