Libraryless. Click here for Pure Java version (1183L/8K/26K).
!752 static class Process { S name; int id; Thread thread; Runnable code; volatile long started, ended; volatile O result; // ? volatile Throwable error; } static new L<Process> processes; static int idCounter; synchronized answer { if "list processes" exceptionToUser { new L l; for (Process p : processes) // drop the problem fields l.add(dropKeys(litlist("thread", "code"), objectToMap(p))); ret slackSnippet(structureLines(l)); } if "test process" { new Process p; p.name = "Test process (sleeps for 10)"; p.code = runnable { sleepSeconds(10); }; ret addProcess(p); } } static S addProcess(final Process p) { p.thread = new Thread() { public void run() { p.started = now(); try { p.code.run(); } catch (Throwable e) { p.error = e; } p.ended = now(); } }; p.id = ++idCounter; processes.add(p); p.thread.start(); ret "Added & started, process id: " + p.id; } static synchronized Process start(S name, Runnable code) { new Process p; p.name = name; p.code = code; addProcess(p); ret p; }
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment