svoid allowDeferredComputation(Runnable r) { try { callF(r); } catch (RuntimeException e) { Throwable e2 = innerException(e); if (!e2 instanceof DeferredComputationException) throw rethrow(e); } } // f1: func -> A, f2 : func(A) -> B, returns: B static O chainDeferrableComputations(O f1, fO f2) { O result; try { result = callF(f1); } catch (RuntimeException e) { Throwable e2 = innerException(e); if (!e2 instanceof DeferredComputationException) throw rethrow(e); final DeferredComputation f = e2/DeferredComputationException.future; final new DeferredComputation future2; f.setContinuation(r { try { future2.setValue(callF(f2, f.getValue())); } catch e { future2.setError(e); } }); throw DeferredComputationException(future2); } ret callF(f2, result); } static <A> A waitThenCompute(int delay, final F0<A> f) { final new DeferredComputation dc; doLater(delay, r { try { dc.setValue(callF(f)); } catch e { dc.setError(e); } }); throw DeferredComputationException(dc); } sclass DeferredComputationException extends QuickException { DeferredComputation future; *(DeferredComputation *future) {} }
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: | #1015715 |
| Snippet name: | Deferred Computation [Include] |
| Eternal ID of this version: | #1015715/3 |
| Text MD5: | b933e46917dbe1ceedbbb0f2b78ea1a1 |
| Author: | stefan |
| Category: | |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2018-05-24 17:49:33 |
| Source code size: | 1234 bytes / 49 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 539 / 594 |
| Version history: | 2 change(s) |
| Referenced in: | [show references] |