]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/OnDestroy.pm
No ext_urls
[public-inbox.git] / lib / PublicInbox / OnDestroy.pm
1 # Copyright (C) all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 package PublicInbox::OnDestroy;
5 use v5.12;
6
7 sub new {
8         shift; # ($class, $cb, @args)
9         bless [ @_ ], __PACKAGE__;
10 }
11
12 sub cancel { @{$_[0]} = () }
13
14 sub DESTROY {
15         my ($cb, @args) = @{$_[0]};
16         if (!ref($cb) && $cb) {
17                 my $pid = $cb;
18                 return if $pid != $$;
19                 $cb = shift @args;
20         }
21         $cb->(@args) if $cb;
22 }
23
24 1;