[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Thoughts on new syntax for toclose
- From: Sean Conner <sean@...>
- Date: Wed, 22 May 2019 00:19:28 -0400
<toclose> could be more useful. In the past, I used to have this
function:
local function dir(path)
local dir = fsys.opendir(path)
return function(d)
return d:next()
end,dir
end
But that would keep the directory open until the next garbage collection and
sometimes, that wasn't enough to keep from exhausting the open file limit.
The code now will close the directory upon reaching the end:
local function dir(path)
local dir = fsys.opendir(path)
return function(d)
local e = d:next()
if not e then d:__gc() end
return e
end,dir
end
It would be nice to have the __close method called at the end of the
interation, but alas, this:
local function dir(path)
local <toclose> dir = fsys.opendir(path)
return function(d)
return d:next()
end,dir
end
does not work---the directory is *immediately* closed before the iteration
starts. It's in the context of iterators that I would love to use
<toclose>.
-spc