Skip to content

Instantly share code, notes, and snippets.

@bigbes
Created August 17, 2018 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigbes/6df663473a7a49e5fe67d5e78ec3a7b0 to your computer and use it in GitHub Desktop.
Save bigbes/6df663473a7a49e5fe67d5e78ec3a7b0 to your computer and use it in GitHub Desktop.
local fiber = require('fiber')
local ch = fiber.channel(0)
local function len(tbl)
local cnt = 0; for _, _ in pairs(tbl) do cnt = cnt + 1 end; return cnt
end
fiber.create(function() while true do print('fiber count:', len(fiber.info())); fiber.sleep(1) end end)
local function closure()
ch:get(10)
end
for k = 1, 20000 do
fiber.create(closure)
fiber.sleep(0.001)
if k % 1000 == 0 then print('running', k, 'fibers') end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment