Mercurial Hosting > luan
comparison src/luan/modules/ThreadLuan.java @ 1322:d5739c101bd6
improve Thread
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 06 Feb 2019 01:11:12 -0700 |
parents | 70eecde81820 |
children | f41919741100 |
comparison
equal
deleted
inserted
replaced
1321:307e76ccd0d6 | 1322:d5739c101bd6 |
---|---|
15 import luan.LuanState; | 15 import luan.LuanState; |
16 import luan.LuanFunction; | 16 import luan.LuanFunction; |
17 import luan.LuanTable; | 17 import luan.LuanTable; |
18 import luan.LuanException; | 18 import luan.LuanException; |
19 import luan.LuanCloner; | 19 import luan.LuanCloner; |
20 import luan.LuanCloneable; | |
20 | 21 |
21 | 22 |
22 public final class ThreadLuan { | 23 public final class ThreadLuan { |
23 private static final Executor exec = Executors.newCachedThreadPool(); | 24 private static final Executor exec = Executors.newCachedThreadPool(); |
24 public static final ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(1); | 25 public static final ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(1); |
153 return obj; | 154 return obj; |
154 a[i] = obj; | 155 a[i] = obj; |
155 } | 156 } |
156 return a; | 157 return a; |
157 } else { | 158 } else { |
158 if( v==null || v instanceof String || v instanceof Boolean || v instanceof Number ) | 159 if( v instanceof LuanCloneable ) |
159 return v; | 160 return new Unsafe("type "+Luan.type(v)); |
160 return new Unsafe("type "+Luan.type(v)); | 161 return v; |
161 } | 162 } |
162 } | 163 } |
163 | 164 |
164 public static final class Callable { | 165 public static final class Callable { |
165 private long expires; | 166 private long expires; |
199 if( callable.expires < now ) | 200 if( callable.expires < now ) |
200 iter.remove(); | 201 iter.remove(); |
201 } | 202 } |
202 } | 203 } |
203 | 204 |
204 public static synchronized Callable globalCallable(LuanState luan,String name,long timeout,LuanTable fns) { | 205 public static synchronized Callable globalCallable(LuanState luan,String name,LuanTable fns,long timeout) { |
205 Callable callable = callableMap.get(name); | 206 Callable callable = callableMap.get(name); |
206 if( callable == null ) { | 207 if( callable == null ) { |
207 sweep(); | 208 sweep(); |
208 callable = new Callable(luan,fns); | 209 callable = new Callable(luan,fns); |
209 callableMap.put(name,callable); | 210 callableMap.put(name,callable); |