aboutsummaryrefslogtreecommitdiff
path: root/tests/func_is_string.lua
blob: 5de4c60d29e2f8cd361351cccc0a59b1c3f8bdca (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
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, dofile('fibonacci.lua')")
local gen2 = lanes.gen(options, { name = 'auto' }, "return b")

fibLane = gen1()
lanes.sleep(0.1)
print(fibLane, fibLane.status)
local _status, _err = fibLane:join()
print(_status, _err)

retLane1, retLane2 = gen2(), gen2()

print( retLane1[1], retLane2[1])
print "TEST OK"