From a363eb15ec96856c011d64612b3e1c9c103853c7 Mon Sep 17 00:00:00 2001 From: "Robert G. Jakabosky" Date: Sat, 7 May 2011 16:56:07 -0700 Subject: [PATCH] Try to use socket.sleep() instead of os.execute('sleep 1') --- tests/test_llthreads.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/test_llthreads.lua b/tests/test_llthreads.lua index 3280a70..e999e4a 100644 --- a/tests/test_llthreads.lua +++ b/tests/test_llthreads.lua @@ -20,6 +20,18 @@ local llthreads = require"llthreads" +local sleep +local status, socket = pcall(require,"socket") +if status then + sleep = function(secs) + return socket.sleep(secs) + end +else + sleep = function(secs) + os.execute("sleep " .. tonumber(secs)) + end +end + local function detached_thread(...) local thread = llthreads.new([[ print("print_detached_thread:", ...) ]], ...) -- start detached thread @@ -43,15 +55,15 @@ end local thread1 = detached_thread("number:", 1234, "nil:", nil, "bool:", true) -os.execute("sleep 1"); +sleep(1) local thread2 = print_thread("number:", 1234, "nil:", nil, "bool:", true) print("thread2:join: results # = ", select('#', thread2:join())) -os.execute("sleep 1"); +sleep(1) local thread3 = pass_through_thread("number:", 1234, "nil:", nil, "bool:", true) print("thread3:join:", thread3:join()) -os.execute("sleep 1"); +sleep(1)