From 6039d6bf2920457fcbb8161b93f440d39f8e65a1 Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Fri, 13 Mar 2020 10:39:57 -0400 Subject: [PATCH] holdWithin/For now accept conns --- changes.md | 1 + multi/init.lua | 23 ++++++++++++++--------- test.lua | 13 +++++++++++-- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/changes.md b/changes.md index cd92bb1..fbbcca4 100644 --- a/changes.md +++ b/changes.md @@ -64,6 +64,7 @@ Added: Fixed: --- +- thread.holdFor(n,func) and thread.holdWithin(n,func) now accept a connection object as the func argument - Issue with threaded functions not handling nil properly from returns. This has been resolved and works as expected. - Issue with system threaded job queues newFunction() not allowing nil returns! This has be addressed and is no longer an issue. - Issue with hold like functions not being able to return `false` diff --git a/multi/init.lua b/multi/init.lua index 87be926..896d209 100644 --- a/multi/init.lua +++ b/multi/init.lua @@ -1195,6 +1195,17 @@ function multi.initThreads(justThreads) end end end + local function holdconn(n) + if type(ret[n])=="table" and ret[n].Type=='connector' then + local letsgo + ret[n](function(...) letsgo = {...} end) + ret[n] = function() + if letsgo then + return unpack(letsgo) + end + end + end + end local function helper(i) if type(ret)=="table" then if ret[1]=="_kill_" then @@ -1215,20 +1226,13 @@ function multi.initThreads(justThreads) threads[i].__ready = false ret = nil elseif ret[1]=="_hold_" then - if type(ret[2])=="table" and ret[2].Type=='connector' then - local letsgo - ret[2](function(...) letsgo = {...} end) - ret[2] = function() - if letsgo then - return unpack(letsgo) - end - end - end + holdconn(2) threads[i].func = ret[2] threads[i].task = "hold" threads[i].__ready = false ret = nil elseif ret[1]=="_holdF_" then + holdconn(3) threads[i].sec = ret[2] threads[i].func = ret[3] threads[i].task = "holdF" @@ -1236,6 +1240,7 @@ function multi.initThreads(justThreads) threads[i].__ready = false ret = nil elseif ret[1]=="_holdW_" then + holdconn(3) threads[i].count = ret[2] threads[i].pos = 0 threads[i].func = ret[3] diff --git a/test.lua b/test.lua index e4b2e18..30cf109 100644 --- a/test.lua +++ b/test.lua @@ -1,5 +1,14 @@ package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path multi, thread = require("multi"):init() - - +conn = multi:newConnection() +func = thread:newFunction(function() + a,b,c = thread.holdFor(.5,conn) + print(a,b) + os.exit() +end) +func() +multi:setTimeout(function() + print("Test!") + conn:Fire(1,2,3) +end,1) multi:lightloop() \ No newline at end of file