Mercurial Hosting > luan
diff src/luan/modules/ThreadLuan.java @ 1563:8fbcc4747091
remove LuanFunction.luan
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 09 Nov 2020 01:37:57 -0700 |
parents | b89212fd04b5 |
children | c922446f53aa |
line wrap: on
line diff
--- a/src/luan/modules/ThreadLuan.java Sun Nov 08 16:50:59 2020 -0700 +++ b/src/luan/modules/ThreadLuan.java Mon Nov 09 01:37:57 2020 -0700 @@ -30,12 +30,12 @@ private static final Executor exec = Executors.newCachedThreadPool(); public static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); - private static Runnable runnable(final LuanFunction fn) { + private static Runnable runnable(final Luan luan,final LuanFunction fn) { return new Runnable() { public synchronized void run() { - LuanLogger.startThreadLogging(fn.luan()); + LuanLogger.startThreadLogging(luan); try { - fn.call(); + fn.call(luan); } catch(LuanException e) { e.printStackTrace(); } finally { @@ -45,10 +45,11 @@ }; } - public static void fork(LuanFunction fn) { + public static void fork(Luan luan,LuanFunction fn) { LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); - final LuanFunction newFn = (LuanFunction)cloner.get(fn); - exec.execute(runnable(newFn)); + luan = (Luan)cloner.get(luan); + fn = (LuanFunction)cloner.get(fn); + exec.execute(runnable(luan,fn)); } private static final Map<String,ScheduledFuture> scheduleds = new WeakCacheMap<String,ScheduledFuture>(); @@ -59,7 +60,7 @@ logger.error(src+" cancel="+b+" isCancelled="+sf.isCancelled()+" isDone="+sf.isDone()+" "+sf); } - public static synchronized void schedule(LuanFunction fn,LuanTable options) + public static synchronized void schedule(Luan luan,LuanFunction fn,LuanTable options) throws LuanException { options = new LuanTable(options); @@ -76,11 +77,10 @@ if( sf != null ) cancel(sf,"id "+id); } - 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); - final Runnable r = runnable(newFn); + final Runnable r = runnable(newLuan,newFn); final ScheduledFuture sf; if( repeatingDelay != null ) { if( delay==null ) @@ -210,7 +210,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(args); + Object rtn = fn.call(luan,args); rtn = makeSafe(rtn); if( rtn instanceof Unsafe ) throw new LuanException("can't return "+((Unsafe)rtn).reason+" from global_callable"); @@ -245,13 +245,13 @@ } - public static Object runInLock(Lock lock,long timeout,LuanFunction fn,Object... args) + public static Object runInLock(Luan luan,Lock lock,long timeout,LuanFunction fn,Object... args) throws LuanException, InterruptedException { if( !lock.tryLock(timeout,TimeUnit.MILLISECONDS) ) throw new LuanException("failed to acquire lock"); try { - return fn.call(args); + return fn.call(luan,args); } finally { lock.unlock(); }