Libraryless. Click here for Pure Java version (1183L/8K/26K).
1 | !752 |
2 | |
3 | static class Process { |
4 | S name; |
5 | int id; |
6 | Thread thread; |
7 | Runnable code; |
8 | volatile long started, ended; |
9 | volatile O result; // ? |
10 | volatile Throwable error; |
11 | } |
12 | |
13 | static new L<Process> processes; |
14 | static int idCounter; |
15 | |
16 | synchronized answer { |
17 | if "list processes" exceptionToUser { |
18 | new L l; |
19 | for (Process p : processes) |
20 | // drop the problem fields |
21 | l.add(dropKeys(litlist("thread", "code"), objectToMap(p))); |
22 | ret slackSnippet(structureLines(l)); |
23 | } |
24 | |
25 | if "test process" { |
26 | new Process p; |
27 | p.name = "Test process (sleeps for 10)"; |
28 | p.code = runnable { |
29 | sleepSeconds(10); |
30 | }; |
31 | ret addProcess(p); |
32 | } |
33 | } |
34 | |
35 | static S addProcess(final Process p) { |
36 | p.thread = new Thread() { |
37 | public void run() { |
38 | p.started = now(); |
39 | try { |
40 | p.code.run(); |
41 | } catch (Throwable e) { |
42 | p.error = e; |
43 | } |
44 | p.ended = now(); |
45 | } |
46 | }; |
47 | p.id = ++idCounter; |
48 | processes.add(p); |
49 | p.thread.start(); |
50 | ret "Added & started, process id: " + p.id; |
51 | } |
52 | |
53 | static synchronized Process start(S name, Runnable code) { |
54 | new Process p; |
55 | p.name = name; |
56 | p.code = code; |
57 | addProcess(p); |
58 | ret p; |
59 | } |
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
Snippet ID: | #1002558 |
Snippet name: | Process Manager Bot (LIVE) |
Eternal ID of this version: | #1002558/1 |
Text MD5: | b1d4d5b3fe9cec75f513fd56bf42049b |
Transpilation MD5: | b126fc271be52f5ed1f69cbb6176dffb |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-02-02 22:04:30 |
Source code size: | 1202 bytes / 59 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 721 / 1399 |
Referenced in: | [show references] |