Download Jar. Uses 3874K of libraries. Compilation Failed (7508L/51K).
1 | !7 |
2 | |
3 | p-experiment { |
4 | callHibernatable(f normalFunction1); |
5 | callHibernatable(f hibernatingFunction1); |
6 | /*for (bool hibernate : ll(false, true)) { |
7 | callHibernatable(curry(f aFunction, hibernate), voidfunc(S s) { |
8 | print("Got result: " + finished); |
9 | }); |
10 | }*/ |
11 | } |
12 | |
13 | // simple version with only one function and no return value |
14 | static void callHibernatable(O f1) { |
15 | try { |
16 | callF(f1); |
17 | } catch (RuntimeException e) { |
18 | Throwable e2 = innerException(e); |
19 | if (e2 instanceof HibernatingTheThread) |
20 | ret; |
21 | throw rethrow(e2); |
22 | } |
23 | } |
24 | |
25 | static O callHibernatable(O f1, O f2) { |
26 | O result; |
27 | try { |
28 | result = callF(f1); |
29 | } catch (RuntimeException e) { |
30 | Throwable e2 = innerException(e); |
31 | if (!e2 instanceof HibernatingTheThread) throw rethrow(e); |
32 | HibernatingTheThread h = cast e2; |
33 | throw HibernatingTheThread(func { |
34 | |
35 | }); |
36 | } |
37 | ret callF(f2, result); |
38 | } |
39 | |
40 | svoid normalFunction1() { |
41 | print("finished"); |
42 | } |
43 | |
44 | svoid hibernatingFunction1() { |
45 | HibernatingTheThread e = new(r { print("finished after hibernation"); }); |
46 | doLater(1000, e); |
47 | throw e; |
48 | } |
49 | |
50 | sS aFunction(bool hibernate) { |
51 | if (hibernate) { |
52 | print("Hibernating for 1s..."); |
53 | HibernatingTheThread e = new(func -> S { |
54 | ret "finished"; |
55 | }); |
56 | doLater(1000, e); |
57 | throw e; |
58 | } else |
59 | ret "hello"; |
60 | } |
61 | |
62 | sclass HibernatingTheThread extends RuntimeException implements Runnable { |
63 | O code; // runnable or F0 |
64 | O continuation; // runnable or vf1 |
65 | |
66 | *() {} |
67 | *(O *code) {} |
68 | |
69 | public void run() { |
70 | callF(continuation, callF(code)); |
71 | } |
72 | } |
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: | #1015709 |
Snippet name: | Thread Hibernation Spike v1 [dev.] |
Eternal ID of this version: | #1015709/10 |
Text MD5: | f8b5ed553d1fec0dbea3009c3496e668 |
Transpilation MD5: | 870b78a6f7c8b5ee0ab1d3981f7ee2ae |
Author: | stefan |
Category: | |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-05-24 16:05:01 |
Source code size: | 1611 bytes / 72 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 472 / 1035 |
Version history: | 9 change(s) |
Referenced in: | [show references] |