Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

33
LINES

< > BotCompany Repo | #1018060 // evalWithTimeoutOrException

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3495L/22K).

1  
// Note: these first 3 syntaxes seem to be wrong
2  
// (not failing on timeout)
3  
static O evalWithTimeoutOrException(fO f, int timeoutMS) {
4  
  ret evalWithTimeoutOrException(timeoutMS, f);
5  
}
6  
7  
static O evalWithTimeoutOrException(int timeoutMS, fO f) {
8  
  ret eitherAOpt(evalWithTimeout(timeoutMS, f));
9  
}
10  
11  
static O evalWithTimeoutOrException(double timeoutSeconds, fO f) {
12  
  ret eitherAOpt(evalWithTimeout(timeoutSeconds, f));
13  
}
14  
15  
// the following 4 syntaxes are ok
16  
static <A> A evalWithTimeoutOrException(int timeoutMS, F0<A> f) {
17  
  Either<O, Thread> e = evalWithTimeout(timeoutMS, f);
18  
  if (e.isA()) ret (A) e.a();
19  
  fail(trim("Timeout after " + timeoutMS + " ms. "
20  
    + unnull(stackTraceForThread(e.b()))));
21  
}
22  
23  
static <A> A evalWithTimeoutOrException(double timeoutSeconds, F0<A> f) {
24  
  ret evalWithTimeoutOrException(toMS_int(timeoutSeconds), f);
25  
}
26  
27  
static <A> A evalWithTimeoutOrException(int timeoutMS, IF0<A> f) {
28  
  ret evalWithTimeoutOrException(timeoutMS, if0ToF0(f));
29  
}
30  
31  
static <A> A evalWithTimeoutOrException(double timeoutSeconds, IF0<A> f) {
32  
  ret evalWithTimeoutOrException(timeoutSeconds, if0ToF0(f));
33  
}

Author comment

Began life as a copy of #1012516

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1018060
Snippet name: evalWithTimeoutOrException
Eternal ID of this version: #1018060/8
Text MD5: a71e9b882744c56b0f9f6d7fd104b189
Transpilation MD5: c971aa5858b67f11f44716d2d0c6b602
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-11-10 10:58:23
Source code size: 1143 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 427 / 537
Version history: 7 change(s)
Referenced in: [show references]