Fetch tree and blob contents lazily#27
Conversation
apis/github
Outdated
| if self.contents then | ||
| return self.contents |
There was a problem hiding this comment.
Can we make this look more private?
At risk of revealing that I now develop python and not lua, perhaps
| if self.contents then | |
| return self.contents | |
| if self._contents then | |
| return self._contents |
There was a problem hiding this comment.
Also, will this fail for empty files? Should it be contents ~= nil?
There was a problem hiding this comment.
Sure, private change committed in 86fb962.
That test will work fine for empty directories - an empty table is a truthy value, unlike nil.
|
Discovered a couple of issues with this PR in testing, will push an update later. |
…FullSize() method.
|
Fixed a few issues with this PR:
Tested and verified the github client against a simple repository - everything is working as expected. |
|
I'm in danger of being nerd-sniped by your is.pullEvent remark, having been involved in writing coroutine schedulers in Python. It's been a while since I've written Lua though... |
|
Perhaps something simple like: sentinel = {}
yield = function(...)
coroutine.yield(sentinel, ...)
end
wrap = function(coro)
native_wrap = coroutine.wrap(coro)
return function(...)
args = pack(...)
while true do
ret = pack(native_wrap(unpack(args))
if ret[1] == sentinel then
return unpack(ret, 1)
end
args = pack(coroutine.yield(unpack(ret)))
end
end
end |
|
It's been a while since I read through the ComputerCraft BIOS/CraftOS internals, so I'm not sure if that would solve the problem...all I recall now is that coroutines (outside of "normal" event loops) were the problem and not using them solved it. 😆 As the ComputerCraft documentation says:
|
|
The idea behind the pseudocode above is to distinguish our yields from theirs, and propagate theirs when they occur. It's definitely not correct as written, I forget how varargs work. |
|
Let's assume the pseudocode works. Do you think it's worth "fixing" ComputerCraft's coroutines in this case, since they're only used in one (relatively minor) place in the library? I agree that it's an interesting intellectual exercise, but I'm not sure it's worth it in this case - I think the simplest solution is probably best. |
Closes #26.
This PR necessarily introduces a small breaking change -
Tree.sizeno longer represents the total size of all files in the tree, only the total size of the files at the top level.Tree:getFullSizeis introduced to return whatTree.sizeoriginally did.In addition to
Blob:getContentsandTree:getContents, a convenience methodTree:getChildhas also been added.