Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use LWP::Simple;
- # return first kept promise(s), await them all only if necessary
- sub kept(@p, :$info=False) {
- @p && await Promise.anyof(@p).then({
- # status output "(Status1, Status2, etc.)" of given promises
- @p>>.status.say if $info;
- # either return kept promises (if any) or await next promise
- (@p.grep: {.status ~~ Kept}) || kept(:$info, @p.grep: {.status !~~ Broken})
- })
- }
- say kept(:info, map { start LWP::Simple.new.get("http://$^a") }, <123456 google.com>)
- ?? "Online" !! "Offline";
- # (Broken, Planned)
- # (Kept)
- # Online
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement