File: ex10.lua

package info (click to toggle)
luasocket 3.0~rc1%2Bgit%2Bac3201d-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 2,216 kB
  • sloc: ansic: 4,487; makefile: 320; sh: 116
file content (17 lines) | stat: -rw-r--r-- 422 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function pump.step(src, snk)
  local chunk, src_err = src()
  local ret, snk_err = snk(chunk, src_err)
  if chunk and ret then return 1
  else return nil, src_err or snk_err end
end

function pump.all(src, snk, step)
    step = step or pump.step
    while true do
        local ret, err = step(src, snk)
        if not ret then
            if err then return nil, err
            else return 1 end
        end
    end
end