Immediate closing of iterators

Chris Hansen renselp at
Tue Jan 2 15:23:00 PST 2007

> > In the absence of finalization none of these problems occur because
> > then the collection or non-collection of an unreachable object cannot
> > be observed from the program.
> Thanks, this is the compelling argument for C#-style close automation
> (i.e., the ES4 spec automates close calling on exit from for-in and
> for-each-in loops only); all other generator use-cases that want
> close must do it themselves.  As I've said several times, I'm in
> agreement.  Is everyone else?

We agree about C#-style close and that's not what I'm arguing for.
I'm arguing against having automatically closing of generators that
are not used in for-in loops, for instance ones used as coroutines.
It's not my impression that we agree there.  But in any case I'll give
it a rest and hopefully someone else will have an opinion on this.

> The important timely-close use-case is the for-in loop. I can't think
> of any others that aren't contrived.

You could easily imagine using generators to access files, networks
sockets or other external resources, and I don't think it is contrived
to imagine such a generator used outside a for-in loop.  In that case
you don't need prompt finalization and that's not what I mean when I
say "timely fashion", but you would want it to happen eventually and
you probably don't want too much time to pass before it happens.

-- Chris

More information about the Es4-discuss mailing list