Am Montag, 2. Mai 2016 17:20:47 UTC+2 schrieb Matija Papec:
>
>
> I want to read from redis in non-blocking way and delay() looks like first 
> choice for this kind of task (event callbacks are closures to session 
> related variables).
>

Using delay() for non-blocking handling of requests (or more specifically 
websocket messages) is fine;
the question was why you try to define the event handlers inside some delay 
step.
I´d suggest re-reading the relevant docs 
(http://mojolicious.org/perldoc/Mojolicious/Guides/Tutorial#WebSockets and 
http://mojolicious.org/perldoc/Mojolicious/Guides/Cookbook#WebSocket-web-service).

Haven´t use websockets myself, yet, but something like this should be ok 
(untested!):

websocket '/ws/:sessid' => sub {
    my ($c) = @_;
    my $sessid = $c->stash('sessid');
    $c->on(finish => sub { warn "disconnect\n" });
    $c->on(json => sub {
        my ($c, $msg) = @_;
        warn "incoming ws json for session $sessid\n";
        $c->delay(
            sub { my $delay = shift; ... read from redis, pass it to delay 
... },
            sub { my ( $delay, $data_from_redis ) = @_; ... do something 
with data ... },
        );
   });
};

If that´s nonsense, somebody please correct me...

-- 
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 https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to