Mercurial Hosting > luan
diff src/luan/modules/ThreadLuan.java @ 1335:e0cf0d108a77
major cleanup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 14 Feb 2019 03:10:45 -0700 |
parents | 25746915a241 |
children | ae2321a09723 |
line wrap: on
line diff
--- a/src/luan/modules/ThreadLuan.java Tue Feb 12 22:53:57 2019 -0700 +++ b/src/luan/modules/ThreadLuan.java Thu Feb 14 03:10:45 2019 -0700 @@ -23,13 +23,12 @@ private static final Executor exec = Executors.newCachedThreadPool(); public static final ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(1); - public static void fork(Luan luan,LuanFunction fn) { + public static void fork(LuanFunction fn) { LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); - final Luan newLuan = (Luan)cloner.clone(luan); final LuanFunction newFn = (LuanFunction)cloner.get(fn); exec.execute(new Runnable(){public void run() { try { - newFn.call(newLuan); + newFn.call(); } catch(LuanException e) { e.printStackTrace(); } @@ -47,15 +46,16 @@ }; } */ - public static void schedule(Luan luan,long delay,LuanFunction fn,String repeating) + public static void schedule(long delay,LuanFunction fn,String repeating) throws LuanException { + Luan luan = fn.luan(); LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); final Luan newLuan = (Luan)cloner.clone(luan); final LuanFunction newFn = (LuanFunction)cloner.get(fn); Runnable r = new Runnable(){public void run() { try { - newFn.call(newLuan); + newFn.call(); } catch(LuanException e) { e.printStackTrace(); } @@ -166,7 +166,7 @@ private final Luan luan = new Luan(); private final LuanTable fns; - Callable(Luan luan,LuanTable fns) { + Callable(LuanTable fns) { LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); this.fns = (LuanTable)cloner.get(fns); } @@ -182,7 +182,7 @@ if( !(f instanceof LuanFunction) ) throw new LuanException("value of '"+fnName+"' not a function in global_callable"); LuanFunction fn = (LuanFunction)f; - Object rtn = fn.call(luan,args); + Object rtn = fn.call(args); rtn = makeSafe(callerLuan,rtn); if( rtn instanceof Unsafe ) throw new LuanException("can't return "+((Unsafe)rtn).reason+" from global_callable"); @@ -201,11 +201,11 @@ } } - public static synchronized Callable globalCallable(Luan luan,String name,LuanTable fns,long timeout) { + public static synchronized Callable globalCallable(String name,LuanTable fns,long timeout) { Callable callable = callableMap.get(name); if( callable == null ) { sweep(); - callable = new Callable(luan,fns); + callable = new Callable(fns); callableMap.put(name,callable); } callable.expires = System.currentTimeMillis() + timeout;