comparison src/luan/modules/Thread.luan @ 1166:7ef40e1923b7

add back Thread.global allow metatables to have metatables
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 08 Feb 2018 02:22:51 -0700
parents 3ef883468fd0
children 9f5edbef3f55
comparison
equal deleted inserted replaced
1165:668f29bc52ea 1166:7ef40e1923b7
51 return tbl 51 return tbl
52 end 52 end
53 53
54 Thread.remove_global_callable = ThreadLuan.removeGlobalCallable 54 Thread.remove_global_callable = ThreadLuan.removeGlobalCallable
55 55
56
57 local map = {}
58 local fns = {}
59
60 function fns.get(key)
61 return map[key]
62 end
63
64 function fns.put(key,value)
65 map[key] = value
66 end
67
68 Thread.global = {} -- shared across threads
69 local global_mt = {}
70 set_metatable(Thread.global,global_mt)
71
72 function global_mt.__index(_,key)
73 return global_mt.fns.get(key)
74 end
75
76 function global_mt.__new_index(_,key,value)
77 global_mt.fns.put(key,value)
78 end
79
80 function Thread.set_global_timeout(timeout)
81 global_mt.fns = Thread.global_callable("Thread.global",timeout,fns)
82 end
83
84 Thread.set_global_timeout(60000) -- one minute
85
86
56 return Thread 87 return Thread