hi, guys,

 Been reading up 
https://docs.mojolicious.org/Mojo/IOLoop/Delay
https://docs.mojolicious.org/Mojolicious/Guides/Cookbook
and a few threads in the group.

Apologies if i had missed this in advance but with Mojo::IOLoop's delay, 
timer, and recurring, can I use them in a promises's "then" clause? 
 I am trying to do that to no avail.

 For example, in the following code snippet,  the test runs very quickly 
and doesn't delay at all.

*Output:*

[16:50:12] anexiole:server git:(bugfix/ET750-asyncTests*) $ prove -v 
t/api/fwm/job/up.t 
t/api/fwm/job/up.t .. 
[info] Setting log level to: debug
[info] Manager started: MG EMU: Mojo::Server::Daemon
[info] Worker started: MG EMU: [27346]
[info] Manager started: MG EMU: Mojo::Server::Daemon
[info] Worker started: MG EMU: [27346]
 Current port of t is 50016
 RESULTS : $VAR1 = '{"jobId":2530,"task":"upgrade"}';
job id is 2530
Get the job out ...
IOLOoP is active
After the ioloop...
1..0
skipped: (no reason given)



*Snippet:*



           my $data = from_json( $test_scenario->{contents}->{data} );

            my $enqueue_job = Mojo::URL->new($url);

            $enqueue_job->query(
                Mojo::Parameters->new(
                    'format'     => 
$test_scenario->{'contents'}->{'format'},
                    'scope'      => $scope,
                    'deviceType' => $data->{'deviceType'},
                    'data'       => $test_scenario->{'contents'}->{'data'},
                )
            );
            print STDERR qq{ Current port of t is }
                . $t->ua->server->url->port . qq{\n};

            $t->ua->post_p( $enqueue_job => $header )->then(
                sub ($tx) {
                    print STDERR qq{ RESULTS : }
                        . Dumper( $tx->result->body );
                    my $job_id = from_json( $tx->result->body )->{'jobId'};
                    print STDERR qq{job id is $job_id\n};

                    # Grab the report of the job out
                    my $retrieve_enqueued_job_url
                        = 
Mojo::URL->new(qq{/myTestApp/api/job/v12/result/$job_id});
                    $retrieve_enqueued_job_url->query(
                        Mojo::Parameters->new( 'format' => q{json}, ),
                    );
                    print STDERR qq{Get the job out ...\n};

                    if ( $t->ua->ioloop->is_running() ) {
                        print STDERR qq{IOLOoP is active\n};
                    }
                    else {
                        print STDERR qq{IOLOoP is not active\n};
                    }
                    *use Mojo::IOLoop::Delay;*
*                    my $delay = Mojo::IOLoop->delay(*
*                        sub ($delay) {*
*                            Mojo::IOLoop->timer( 3 => $delay->begin );*
*                        },*
*                        sub ($delay) {*
*                            print STDERR '3 seconds';*
*                            Mojo::IOLoop->timer( 3 => $delay->begin );*
*                        },*
*                        sub ($delay) {*
*                            print STDERR '6 seconds';*
*                            Mojo::IOLoop->timer( 3 => $delay->begin );*
*                        },*
*                        sub ($delay) { print STDERR '9 seconds'; }*
*                    );*
*                    $delay->wait;*

                    $t->ua->get_p( $retrieve_enqueued_job_url => $header 
)->then(
                        sub ($tx) {
                            print STDERR qq{ the job RESULTS : }
                                . Dumper( $tx->result->body );
                        }
                    );

                    print STDERR qq{After the ioloop...\n};

                }
            )->catch(
                sub (@errors) {
                    print STDERR qq{Job retrieval errors: } . 
Dumper(@errors);
                }
            )->wait;
    }


Thank you

Gordon Yeong.


-- 
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.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/edfc52f0-bc7d-484c-91fa-1d64c10be9a9n%40googlegroups.com.

Reply via email to