mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 01:49:44 +00:00
refactor: split io_stream
This commit is contained in:
parent
48680d975f
commit
3617e01d21
7 changed files with 428 additions and 406 deletions
19
res/modules/internal/stream/blocking.lua
Normal file
19
res/modules/internal/stream/blocking.lua
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue