File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
src/main/java/org/byteskript/skript/runtime Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -276,6 +276,35 @@ public Collection<OperationController> getProcesses() {
276276 return processes ;
277277 }
278278
279+ /**
280+ * Runs a runnable on a script thread.
281+ * This is designed for running anonymous script chunks.
282+ * This can also be used to run code that did not originate from a script as though it did.
283+ *
284+ * @param executable the runnable code
285+ * @return a future for the script's halting completion
286+ */
287+ public Future <?> runScript (final Runnable executable ) {
288+ final OperationController controller = new OperationController (skript , factory );
289+ final ScriptFinishFuture future = new ScriptFinishFuture (this );
290+ final Runnable runnable = () -> {
291+ final ScriptThread thread = (ScriptThread ) Thread .currentThread ();
292+ future .thread = thread ;
293+ thread .variables .clear ();
294+ thread .initiator = null ;
295+ thread .event = null ;
296+ try {
297+ executable .run ();
298+ } catch (ThreadDeath ignore ) {
299+ // This is likely from an exit the current process effect, we don't want to make noise
300+ } finally {
301+ future .finish ();
302+ }
303+ };
304+ factory .newThread (controller , runnable , true ).start ();
305+ return future ;
306+ }
307+
279308 /**
280309 * Runs a script with a completing future.
281310 * This is designed for use in places like JUnit tests that require throttling.
You can’t perform that action at this time.
0 commit comments