aboutsummaryrefslogtreecommitdiff
path: root/tests/func_is_string.lua
blob: 3c91603c53e317b62a9ac47e7c3b4be3794725f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
local lanes = require "lanes"

-- Lua 5.4 specific:
if _VERSION >= "Lua 5.4" then
    -- go through a string so that the script we are in doesn't trigger a parse error with older Lua
    local res = assert(load [[
        local lanes = require 'lanes'
        local r
        do
            local h <close> = lanes.gen('*', { name = 'auto' }, lanes.sleep)(0.5)
            r = h
        end -- h is closed here
        return r.status
    ]])()
    -- when the do...end block is exited, the to-be-closed variable h is closed, which internally calls h:join()
    -- therefore the status of the lane should be "done"
    assert(res == "done")
    print("close result:", res)
end


local options = {globals = { b = 666 }}

local gen1 = lanes.gen("*", { name = 'auto' }, "return true, error('bob')")

fibLane = gen1()
lanes.sleep(0.1)
print(fibLane, fibLane.status)
local _r, _err, _stk = fibLane:join()
assert(_r == nil, "got " .. tostring(_r) .. " " .. tostring(_err) .. " " .. tostring(_stk))

local gen2 = lanes.gen(options, { name = 'auto' }, "return b")
local retLane1, retLane2 = gen2(), gen2()

print( retLane1[1], retLane2[1])
assert(retLane1[1] == 666 and retLane2[1] == 666)
print "TEST OK"