Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub any {
- my ($class, @promises) = @_;
- my $any = $class->new;
- my $rejections = [];
- my $remaining = scalar @promises;
- for my $i (0 .. $#promises) {
- $promises[$i]->then(
- sub { $any->resolve(@_) },
- sub {
- $rejections[$i] = [ @_ ];
- $any->reject(@$rejections) if --$remaining <= 0;
- }
- );
- }
- return $any;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement