Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to use Promise.in with infinite time?

Tags:

promise

raku

Is there a direct way to use Promise.in (or other sub/method/class) to achieve an indefinite amount of time? In other words the Promise is never resolved.

Currently I'm checking the $time when the promise is kept to see if an indefinite time was requested (indicated by negative or 0 value) and preventing the react block from exiting.

Is isn't a terrible solution, but is there are more idiomatic way of achieving this?

my $time=0;
react {
    whenever Promise.in($time) {
          #check if time is 0
          done if $time > 0;
    }
    whenever signal(SIGINT) {
        done;
    }

    #whenever Supply...{
    #}
}
like image 933
drclaw Avatar asked Aug 29 '19 01:08

drclaw


2 Answers

You can actually pass Inf to Promise.in, like this:

await Promise.in(Inf);
say "never happens";
like image 152
timotimo Avatar answered Sep 19 '22 23:09

timotimo


whenever Promise.new {

pretty much gives you a promise that will never be kept, so the associated code will never fire. Not sure why you would do that, though.

like image 26
Elizabeth Mattijsen Avatar answered Sep 22 '22 23:09

Elizabeth Mattijsen