Skip to content

Instantly share code, notes, and snippets.

@Xliff
Created September 8, 2023 22:29
Show Gist options
  • Save Xliff/976f3808165cd91405a903f5cd14aa85 to your computer and use it in GitHub Desktop.
Save Xliff/976f3808165cd91405a903f5cd14aa85 to your computer and use it in GitHub Desktop.
Running an asyncronous piece of code at a later date

I have a piece of asyncronous code I would like to run at a later date. I figured a Promise would suit this purpose fine.

So far this is what I have:

sub makePromise ( $o, $m, :$in = 0, :$args = @() ) {
  my $p = Promise.new;

  for $args {
    .wrap({
      nextsame;
      $p.keep;
    }) if Callable;
  }

  $o."$m"( |$args );

  $p;
}

Am I missing anything....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment