Skip to content

Instantly share code, notes, and snippets.

@sharonovd
Created January 24, 2019 08:11
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 sharonovd/0abca667c3b8641d9807320d244e3c8f to your computer and use it in GitHub Desktop.
Save sharonovd/0abca667c3b8641d9807320d244e3c8f to your computer and use it in GitHub Desktop.
local fiber = require('fiber')
function another_func()
fiber.sleep(1)
fiber.yield()
end
function test()
local fib = fiber.create(another_func)
fib:set_joinable(true)
fib:join()
end
tasks = {}
function start(func, name)
local worker = fiber.create(function()
while true do
local ok, _ = pcall(func)
fiber.testcancel()
fiber.sleep(0.1)
end
end)
tasks[name] = worker
end
function stop(name)
tasks[name]:cancel()
end
start(test, 'test')
stop('test')
while tasks[name] and tasks[name]:status() ~= 'dead' do
print 'Not ok'
print(tasks[name]:status())
fiber.sleep(1)
end
print 'Success!'
@sharonovd
Copy link
Author

This leads to:

tarantool> d:tmp d.sharonov$ tarantool -i test.lua
Success!
Tarantool 1.10.2-66-g2972cfcee
type 'help' for interactive help
tarantool> tasks
---
- test:
    status: suspended
    name: lua
    id: 102
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment