Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improved streaming recipe slightly
  • Loading branch information
kraih committed Nov 10, 2011
1 parent 3c87812 commit ffd944e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/Message.pm
Expand Up @@ -643,7 +643,7 @@ Check if message is at least a specific version.
$message = $message->body('Hello!');
my $cb = $message->body(sub {...});
Access C<content> data or replace all C<read> events.
Access C<content> data or replace all subscribers of the C<read> event.
$message->body(sub {
my ($message, $chunk) = @_;
Expand Down
9 changes: 4 additions & 5 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -457,15 +457,14 @@ L<Mojo::UserAgent> makes it actually easy.

my $ua = Mojo::UserAgent->new;
my $tx = $ua->build_tx(GET => 'http://mojolicio.us');
$tx->res->body(sub {
my ($res, $chunk) = @_;
$tx->res->content->unsubscribe('read')->on(read => sub {
my ($content, $chunk) = @_;
say "Streaming: $chunk";
});
$ua->start($tx);

The C<body> method can be used to replace all C<read> events, which will be
emitted for every chunk of data that is received, even C<chunked> encoding
will be handled transparently if necessary.
The C<read> event will be emitted for every chunk of data that is received,
even C<chunked> encoding will be handled transparently if necessary.

=head2 Streaming request

Expand Down

0 comments on commit ffd944e

Please sign in to comment.