> On 12 Jan 2016, at 04:49, Dave Rolsky (via RT) <perl6-bugs-follo...@perl.org> 
> wrote:
> 
> # New Ticket Created by  Dave Rolsky 
> # Please include the string:  [perl #127243]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org/Ticket/Display.html?id=127243 >
> 
> 
> Here's an example which might demonstrate why this is important:
> 
> class C {
>    has @.threads;
>    method foo {
>        @!threads = (^10).map: {
>            Thread.start(
>                name => $_,
>                sub {
>                    sleep 1;
>                    say $*THREAD.name;
>                }
>            )
>        };
>        say @!threads;
>    };
>    submethod DESTROY {
>        say 'bye';
>        .finish for @!threads;
>    };
> };
> 
> my $c = C.new;
> $c.foo;
> exit 0;
> 
> While there are various workarounds, it seems like that all force the _user_ 
> of the class to explicitly account for the need to cleanup threads created by 
> C. It seems like a class should be fully self-contained and capable of 
> cleaning up after itself.

At exit, all threads are cleaned up automatically anyway, so I don’t really 
think this is a problem in *this* case.

More generally, I think it would be nice if an import would be able to import a 
LEAVE phaser into the scope: this then would allow code to be executed whenever 
the importing scope would be left (which an exit would do).

  $ 6 'LEAVE say "goodbye"; exit’
  $ 6 'LEAVE say "goodbye"’
  goodbye

OTOH, it looks like exit() is not honouring LEAVE phasers either…  hmmmm….



Liz

Reply via email to