Skip to content

Instantly share code, notes, and snippets.

Created December 19, 2012 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4337123 to your computer and use it in GitHub Desktop.
Save anonymous/4337123 to your computer and use it in GitHub Desktop.
for(..) is not the async solution
package MyApp::MyController;
use Mojo::Base 'Mojolicious::Controller';
sub some_ws_callback {
my $self = shift;
my $i = 0;
# this is your loop mr.!
my $cb = sub {
my $self = shift;
$i++ > 10 ? $self->finish : $self->send($i);
};
$self->$cb;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment