Fixed issue with threads not returning values properly
This commit is contained in:
parent
3f046afaa1
commit
264867a0da
@ -1207,7 +1207,7 @@ function thread:newFunctionBase(generator,holdme)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
local t = generator(...)
|
local t = generator(...)
|
||||||
t.OnDeath(function(self,status,...) rets = {...} end)
|
t.OnDeath(function(...) rets = {...} end)
|
||||||
t.OnError(function(self,e) err = e end)
|
t.OnError(function(self,e) err = e end)
|
||||||
if holdme then
|
if holdme then
|
||||||
return wait()
|
return wait()
|
||||||
@ -1223,7 +1223,7 @@ function thread:newFunctionBase(generator,holdme)
|
|||||||
end,
|
end,
|
||||||
connect = function(f)
|
connect = function(f)
|
||||||
local tempConn = multi:newConnection(true)
|
local tempConn = multi:newConnection(true)
|
||||||
t.OnDeath(function(self,status,...) if f then f(...) else tempConn:Fire(...) end end)
|
t.OnDeath(function(...) if f then f(...) else tempConn:Fire(...) end end)
|
||||||
t.OnError(function(self,err) if f then f(nil,err) else tempConn:Fire(nil,err) end end)
|
t.OnError(function(self,err) if f then f(nil,err) else tempConn:Fire(nil,err) end end)
|
||||||
return tempConn
|
return tempConn
|
||||||
end
|
end
|
||||||
@ -1325,6 +1325,7 @@ function thread:newThread(name,func,...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
c.Destroy = c.Kill
|
c.Destroy = c.Kill
|
||||||
|
|
||||||
if self.Type=="process" then
|
if self.Type=="process" then
|
||||||
table.insert(self.threads,c)
|
table.insert(self.threads,c)
|
||||||
table.insert(self.startme,c)
|
table.insert(self.startme,c)
|
||||||
@ -1332,6 +1333,7 @@ function thread:newThread(name,func,...)
|
|||||||
table.insert(threads,c)
|
table.insert(threads,c)
|
||||||
table.insert(startme,c)
|
table.insert(startme,c)
|
||||||
end
|
end
|
||||||
|
|
||||||
startme_len = #startme
|
startme_len = #startme
|
||||||
globalThreads[c] = multi
|
globalThreads[c] = multi
|
||||||
threadid = threadid + 1
|
threadid = threadid + 1
|
||||||
@ -1476,33 +1478,32 @@ local co_status = {
|
|||||||
cmds[r1](ref,r2,r3,r4,r5)
|
cmds[r1](ref,r2,r3,r4,r5)
|
||||||
r1=nil r2=nil r3=nil r4=nil r5=nil
|
r1=nil r2=nil r3=nil r4=nil r5=nil
|
||||||
end,
|
end,
|
||||||
["normal"] = function(thd,ref) print("Normal Status") io.read() end, -- Not sure if I will handle this
|
["normal"] = function(thd,ref) end,
|
||||||
["running"] = function(thd,ref) print("Running Status") io.read() end,
|
["running"] = function(thd,ref) end,
|
||||||
["dead"] = function(thd,ref,task,i)
|
["dead"] = function(thd,ref,task,i,th)
|
||||||
if _ then
|
if _ then
|
||||||
ref.OnDeath:Fire(ret,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16)
|
ref.OnDeath:Fire(ret,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16)
|
||||||
else
|
else
|
||||||
ref.OnError:Fire(ref,ret)
|
ref.OnError:Fire(ref,ret)
|
||||||
end
|
end
|
||||||
if i then
|
if i then
|
||||||
table.remove(threads,i)
|
table.remove(th,i)
|
||||||
else
|
else
|
||||||
for i,v in pairs(threads) do
|
for i,v in pairs(th) do
|
||||||
if v.thread==thd then
|
if v.thread==thd then
|
||||||
table.remove(threads,i)
|
table.remove(th,i)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
_=nil r1=nil r2=nil r3=nil r4=nil r5=nil
|
_=nil r1=nil r2=nil r3=nil r4=nil r5=nil
|
||||||
--self.setType(ref,self.DestroyedObj)
|
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
local handler = coroutine.wrap(function(self)
|
local handler = coroutine.wrap(function(self)
|
||||||
while true do
|
while true do
|
||||||
for start = startme_len,1,-1 do
|
for start = startme_len,1,-1 do
|
||||||
_,ret,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16 = resume(startme[start].thread,unpack(startme[start].startArgs))
|
_,ret,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16 = resume(startme[start].thread,unpack(startme[start].startArgs))
|
||||||
co_status[status(startme[startme_len].thread)](startme[startme_len].thread,startme[startme_len],t_none) -- Make sure there was no error
|
co_status[status(startme[startme_len].thread)](startme[startme_len].thread,startme[startme_len],t_none,nil,threads) -- Make sure there was no error
|
||||||
startme[startme_len] = nil
|
startme[startme_len] = nil
|
||||||
startme_len = #startme
|
startme_len = #startme
|
||||||
yield()
|
yield()
|
||||||
@ -1513,7 +1514,7 @@ local handler = coroutine.wrap(function(self)
|
|||||||
task = ref.task
|
task = ref.task
|
||||||
thd = ref.thread
|
thd = ref.thread
|
||||||
ready = ref.__ready
|
ready = ref.__ready
|
||||||
co_status[status(thd)](thd,ref,task,i)
|
co_status[status(thd)](thd,ref,task,i,threads)
|
||||||
end
|
end
|
||||||
yield()
|
yield()
|
||||||
end
|
end
|
||||||
@ -1526,7 +1527,7 @@ function multi:createHandler(threads,startme)
|
|||||||
while true do
|
while true do
|
||||||
for start = #startme,1,-1 do
|
for start = #startme,1,-1 do
|
||||||
_,ret,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16 = resume(startme[start].thread,unpack(startme[start].startArgs))
|
_,ret,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16 = resume(startme[start].thread,unpack(startme[start].startArgs))
|
||||||
co_status[status(startme[start].thread)](startme[start].thread,startme[start],t_none) -- Make sure there was no error
|
co_status[status(startme[start].thread)](startme[start].thread,startme[start],t_none,nil,threads) -- Make sure there was no error
|
||||||
table.remove(startme)
|
table.remove(startme)
|
||||||
yield()
|
yield()
|
||||||
end
|
end
|
||||||
@ -1536,7 +1537,7 @@ function multi:createHandler(threads,startme)
|
|||||||
task = ref.task
|
task = ref.task
|
||||||
thd = ref.thread
|
thd = ref.thread
|
||||||
ready = ref.__ready
|
ready = ref.__ready
|
||||||
co_status[status(thd)](thd,ref,task,i)
|
co_status[status(thd)](thd,ref,task,i,threads)
|
||||||
end
|
end
|
||||||
yield()
|
yield()
|
||||||
end
|
end
|
||||||
|
|||||||
20
test4.lua
20
test4.lua
@ -27,23 +27,13 @@ end,1)
|
|||||||
-- end)
|
-- end)
|
||||||
|
|
||||||
local func = proc:newFunction(function(a,b,c)
|
local func = proc:newFunction(function(a,b,c)
|
||||||
print("Testing proc functions!",a,b,c)
|
print("Testing proc functions!")
|
||||||
for i=1,10 do
|
error("Testing")
|
||||||
thread.sleep(1)
|
return "Please", "Smile", 123
|
||||||
print("h1")
|
|
||||||
end
|
|
||||||
return true,"Smile"
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
thread:newThread(function()
|
func("Some","tests","needed").connect(function(a,b,c)
|
||||||
thread.sleep(3.1)
|
print("Return",a,b,c)
|
||||||
proc.Stop()
|
|
||||||
thread.sleep(3)
|
|
||||||
proc.Start()
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func("Some","tests","needed").connect(print)
|
|
||||||
|
|
||||||
multi:mainloop()
|
multi:mainloop()
|
||||||
Loading…
x
Reference in New Issue
Block a user