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).

// Note: these first 3 syntaxes seem to be wrong
// (not failing on timeout)
static O evalWithTimeoutOrException(fO f, int timeoutMS) {
  ret evalWithTimeoutOrException(timeoutMS, f);
}

static O evalWithTimeoutOrException(int timeoutMS, fO f) {
  ret eitherAOpt(evalWithTimeout(timeoutMS, f));
}

static O evalWithTimeoutOrException(double timeoutSeconds, fO f) {
  ret eitherAOpt(evalWithTimeout(timeoutSeconds, f));
}

// the following 4 syntaxes are ok
static <A> A evalWithTimeoutOrException(int timeoutMS, F0<A> f) {
  Either<O, Thread> e = evalWithTimeout(timeoutMS, f);
  if (e.isA()) ret (A) e.a();
  fail(trim("Timeout after " + timeoutMS + " ms. "
    + unnull(stackTraceForThread(e.b()))));
}

static <A> A evalWithTimeoutOrException(double timeoutSeconds, F0<A> f) {
  ret evalWithTimeoutOrException(toMS_int(timeoutSeconds), f);
}

static <A> A evalWithTimeoutOrException(int timeoutMS, IF0<A> f) {
  ret evalWithTimeoutOrException(timeoutMS, if0ToF0(f));
}

static <A> A evalWithTimeoutOrException(double timeoutSeconds, IF0<A> f) {
  ret evalWithTimeoutOrException(timeoutSeconds, if0ToF0(f));
}

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: 425 / 533
Version history: 7 change(s)
Referenced in: [show references]