aboutsummaryrefslogtreecommitdiff
path: root/unit_tests/scripts/lane/body_is_a_c_function.lua
blob: d8d329f2428ca1da59e78af8583db351a99a077d (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
local lanes = require "lanes".configure()

-- ##################################################################################################
-- ##################################################################################################
-- ##################################################################################################

-- we can create a generator where the lane body is a C function
do
    local b, g = pcall(lanes.gen, "*", print)
    assert(b == true and type(g) == "function")
    -- we can start the lane
    local b, h = pcall(g, "hello")
    -- the lane runs normally
    h:join()
    assert(h.status == "done")
end

-- we can create a generator where the lane body is a C function that raises an error
do
    local b, g = pcall(lanes.gen, "*", error)
    assert(b == true and type(g) == "function")
    -- we can start the lane
    local b, h = pcall(g, "this is an error")
    -- this provides the error that occurred in the lane
    local s, e, t = h:join()
    assert(h.status == "error")
    assert(s == nil and e == "this is an error" and t == nil)
end