From 3589b8e04ecc7e02674547c4738a54954f6758bc Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Tue, 11 Jun 2024 14:56:52 +0200 Subject: New lane:__close does a lane:join() --- tests/func_is_string.lua | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/func_is_string.lua b/tests/func_is_string.lua index d7cf0b2..a14c460 100644 --- a/tests/func_is_string.lua +++ b/tests/func_is_string.lua @@ -1,13 +1,36 @@ local lanes = require "lanes" -lanes.configure() + +-- 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 = lanes.gen('*', 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("*", "dofile('fibonacci.lua')") +local gen1 = lanes.gen("*", "return true, dofile('fibonacci.lua')") local gen2 = lanes.gen(options, "return b") --- fibLane = gen1() +fibLane = gen1() +lanes.sleep(0.1) +print(fibLane, fibLane.status) +local _status, _err = fibLane:join() +print(_status, _err) + retLane1, retLane2 = gen2(), gen2() --- fibLane:join() print( retLane1[1], retLane2[1]) +print "TEST OK" \ No newline at end of file -- cgit v1.2.3-55-g6feb