daily pastebin goal
7%
SHARE
TWEET

am-i-online

a guest Dec 5th, 2017 117 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use LWP::Simple;
  2.  
  3. # return first kept promise(s), await them all only if necessary
  4. sub kept(@p, :$info=False) {
  5.     @p && await Promise.anyof(@p).then({
  6.         # status output "(Status1, Status2, etc.)" of given promises
  7.         @p>>.status.say if $info;
  8.         # either return kept promises (if any) or await next promise
  9.         (@p.grep: {.status ~~ Kept}) || kept(:$info, @p.grep: {.status !~~ Broken})
  10.     })
  11. }
  12.  
  13. say kept(:info, map { start LWP::Simple.new.get("http://$^a") }, <123456 google.com>)
  14.     ?? "Online" !! "Offline";
  15. # (Broken, Planned)
  16. # (Kept)
  17. # Online
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top