Skip to content

Mojo::Promise timer chaining #2281

@maros

Description

@maros

Documentation at https://metacpan.org/pod/Mojo::Promise#timer states that it should be possible to chain a timer to an existing promise.
Hence I would expect following code to produce output where the two timestamps are ten seconds apart.

use Mojo::Promise;
my $p1 = Mojo::Promise->new();
my $p2 = $p1
     ->then(sub { say time })
     ->timer(10)
     ->then(sub{ say time }); 
$p1->resolve;
$p2->wait;

However this exampe terminates immediately without waiting 10 seconds in-between the two outputs.

In comparison, the following code works as expected

use Mojo::Promise;
my $p1 = Mojo::Promise->new();
my $p2 = $p1
     ->then(sub { say time; Mojo::Promise->timer(10) })
     ->then(sub{ say time }); 
$p1->resolve;
$p2->wait;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions