!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 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; }