Advertisement
Guest User

am-i-online

a guest
Dec 5th, 2017
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.57 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement