@@ -66,6 +66,7 @@ M.do_memo=function(linda,memo,timeout)
66
66
if linda :send ( timeout , memo .task , memo ) then -- send on memo.task (a public name of another task)
67
67
if memo .id then
68
68
local ok ,r = linda :receive ( timeout , memo .id ) -- receive the result on memo.id
69
+ linda :set (memo .id ) -- cleanup
69
70
-- log("memo",memo.task,memo.id,"done")
70
71
return r
71
72
end
@@ -204,6 +205,7 @@ M.tasks_functions.claim_global=function(tasks,name,value)
204
205
memo .value = value
205
206
if tasks .linda :send ( nil , memo .task , memo ) then -- send on memo.task (a public name of another task)
206
207
local ok ,r = tasks .linda :receive ( nil , memo .id ) -- receive the result on memo.id
208
+ tasks .linda :set (memo .id ) -- cleanup
207
209
return r .result
208
210
end
209
211
end
@@ -228,6 +230,7 @@ M.tasks_functions.eject_global=function(tasks,name)
228
230
memo .name = name
229
231
if tasks .linda :send ( nil , memo .task , memo ) then -- send on memo.task (a public name of another task)
230
232
local ok ,r = tasks .linda :receive ( nil , memo .id ) -- receive the result on memo.id
233
+ tasks .linda :set (memo .id ) -- cleanup
231
234
return r .result
232
235
end
233
236
end
@@ -250,6 +253,7 @@ M.tasks_functions.fetch_global=function(tasks,name)
250
253
memo .name = name
251
254
if tasks .linda :send ( nil , memo .task , memo ) then -- send on memo.task (a public name of another task)
252
255
local ok ,r = tasks .linda :receive ( nil , memo .id ) -- receive the result on memo.id
256
+ tasks .linda :set (memo .id ) -- cleanup
253
257
return r .result
254
258
end
255
259
end
@@ -571,7 +575,8 @@ M.tasks_functions.receive=function(tasks,memo,timeout)
571
575
tasks :send (memo ,timeout )
572
576
end
573
577
memo .state = " receiving"
574
- local ok ,result = (tasks .main_thread and tasks .colinda or tasks .linda ):receive ( timeout , memo .id )
578
+ local ok ,result = (tasks .main_thread and tasks .colinda or tasks .linda ):receive ( timeout , memo .id ) ;
579
+ (tasks .main_thread and tasks .colinda or tasks .linda ):set (memo .id ) -- cleanup
575
580
memo .state = " done"
576
581
tasks :del_memo (memo )
577
582
@@ -712,11 +717,14 @@ M.colinda_functions.send=function(colinda,...)
712
717
local timestart
713
718
if timeout then timestart = os.time () end
714
719
720
+ -- PRINT(timeout)
721
+ -- TRACEBACK()
722
+
715
723
local ret
716
724
repeat
717
- ret = { colinda .linda :send (0 ,unpack (aa )) }
725
+ ret = { colinda .linda :send (1 ,unpack (aa )) }
718
726
if ret [1 ] then break end -- got a result
719
- if timeout and os.time () > timestart + timeout then break end
727
+ if timeout and os.time () >= timestart + timeout then break end
720
728
coroutine.yield ()
721
729
until false
722
730
@@ -734,9 +742,9 @@ M.colinda_functions.receive=function(colinda,...)
734
742
735
743
local ret
736
744
repeat
737
- ret = { colinda .linda :receive (0 ,unpack (aa )) }
745
+ ret = { colinda .linda :receive (1 ,unpack (aa )) }
738
746
if ret [1 ] then break end -- got a result
739
- if timeout and os.time () > timestart + timeout then break end
747
+ if timeout and os.time () >= timestart + timeout then break end
740
748
coroutine.yield ()
741
749
until false
742
750
0 commit comments