mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-20 09:29:44 +00:00
19 lines
441 B
Lua
19 lines
441 B
Lua
local wrapper = require "internal/stream/wrapper"
|
|
|
|
local blocking = wrapper.extend({})
|
|
|
|
function blocking.new(inner)
|
|
return setmetatable({ inner = inner }, blocking)
|
|
end
|
|
|
|
function blocking:read(n)
|
|
local result = self.inner:read(n)
|
|
while #result < n do
|
|
coroutine.yield()
|
|
if not self.inner:is_alive() then break end
|
|
result:append(self.inner:read(n - #result))
|
|
end
|
|
return result
|
|
end
|
|
|
|
return blocking
|