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

44
LINES

< > BotCompany Repo | #1009330 // Test evalWithTimeout [OK]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (2176L/15K/50K).

!7

p {
  // Easy case - finishes in time
  
  print("Test 1");
  Either<O, Thread> e = evalWithTimeout(1500, f f);
  assertEquals(0, l(evalWithTimeout_inTime));
  while (l(evalWithTimeout_allThreads) > 0) sleep(1);
  assertEqualsVerbose("yo!", e.a());
  
  // Medium case - is in sleep or wait, interruptible
  
  print("Test 2");
  e = evalWithTimeout(500, f f);
  assertEquals(0, l(evalWithTimeout_inTime));
  assertTrue(e.isB());
  assertTrue(l(evalWithTimeout_allThreads) <= 1);
  
  while (l(evalWithTimeout_allThreads) > 0) sleep(1);
  
  // Hard case - busy computing, doesn't call ping
  
  print("Test 3");
  e = evalWithTimeout(500, f g);
  assertEquals(0, l(evalWithTimeout_inTime));
  sleep(10);
  assertEquals(1, l(evalWithTimeout_allThreads));
  assertTrue(e.isB());
  
  while (l(evalWithTimeout_allThreads) > 0) sleep(1);
  
  print("All OK");
}

static S f() {
  sleep(1000);
  ret print("yo!");
}

static S g() {
  busySleepSeconds_noPing(1);
  ret print("yo!");
}

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: #1009330
Snippet name: Test evalWithTimeout [OK]
Eternal ID of this version: #1009330/14
Text MD5: 501f83fb11cfa7135b40f9a8a8c18980
Transpilation MD5: 45b16c471370591c457afe89c68ad37b
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-10-31 23:48:30
Source code size: 1026 bytes / 44 lines
Pitched / IR pitched: No / No
Views / Downloads: 486 / 612
Version history: 13 change(s)
Referenced in: [show references]