Mercurial Hosting > luan
comparison src/luan/modules/http/jetty/HttpServicer.java @ 1154:bbad9a21277c
remove Http.run_later
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 04 Feb 2018 20:34:56 -0700 |
parents | 1f4da56abd4f |
children | 3ef883468fd0 |
comparison
equal
deleted
inserted
replaced
1153:1f4da56abd4f | 1154:bbad9a21277c |
---|---|
168 LuanFunction newResponseFn = (LuanFunction)module.rawGet("new_response"); | 168 LuanFunction newResponseFn = (LuanFunction)module.rawGet("new_response"); |
169 newResponseFn.call( luan, new Object[]{responseTbl} ); | 169 newResponseFn.call( luan, new Object[]{responseTbl} ); |
170 module.rawPut("response",responseTbl); | 170 module.rawPut("response",responseTbl); |
171 | 171 |
172 fn.call(luan); | 172 fn.call(luan); |
173 handle_run_later(luan); | |
174 return true; | 173 return true; |
175 } | 174 } |
176 | 175 |
177 public static void setResponse(LuanTable responseTbl,HttpServletResponse response) throws LuanException { | 176 public static void setResponse(LuanTable responseTbl,HttpServletResponse response) throws LuanException { |
178 int status = Luan.asInteger(responseTbl.rawGet("status")); | 177 int status = Luan.asInteger(responseTbl.rawGet("status")); |
245 } | 244 } |
246 response.addCookie(cookie); | 245 response.addCookie(cookie); |
247 } | 246 } |
248 } | 247 } |
249 | 248 |
250 | |
251 | |
252 private static String RUN_LATER_KEY = "Http.run_later"; | |
253 private static final Executor exec = Executors.newSingleThreadExecutor(); | |
254 | |
255 public static void run_later(final LuanState luan,final LuanFunction fn,final Object... args) { | |
256 List list = (List)luan.registry().get(RUN_LATER_KEY); | |
257 if( list == null ) { | |
258 list = new ArrayList(); | |
259 luan.registry().put(RUN_LATER_KEY,list); | |
260 } | |
261 list.add( | |
262 new Runnable(){public void run() { | |
263 try { | |
264 fn.call(luan,args); | |
265 } catch(LuanException e) { | |
266 e.printStackTrace(); | |
267 } | |
268 }} | |
269 ); | |
270 } | |
271 | |
272 private static void handle_run_later(LuanState luan) { | |
273 List list = (List)luan.registry().get(RUN_LATER_KEY); | |
274 if( list==null ) | |
275 return; | |
276 for( Object obj : list ) { | |
277 exec.execute((Runnable)obj); | |
278 } | |
279 } | |
280 } | 249 } |