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

11
LINES

< > BotCompany Repo | #1024356 // sleepWhile - poll predicate every 50 ms, end after 10 seconds (values changeable)

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

Libraryless. Click here for Pure Java version (8017L/45K).

1  
// returns last value of predicate
2  
sbool sleepWhile(IF0<Bool> pred, O... _) {
3  
  optPar int interval = 50; // ms
4  
  optPar double max = 10.0; // seconds
5  
  long time = sysNow();
6  
  do {
7  
    if (!pred!) false;
8  
    sleep(interval);
9  
  } while (sysNow() <= time+toMS(max));
10  
  true;
11  
}

Author comment

Began life as a copy of #1015681

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1024356
Snippet name: sleepWhile - poll predicate every 50 ms, end after 10 seconds (values changeable)
Eternal ID of this version: #1024356/6
Text MD5: 27b096a895208bbf8a8c716228de0c1b
Transpilation MD5: 46db857ae3190a63836ca7546d898f2d
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-08-28 15:41:46
Source code size: 285 bytes / 11 lines
Pitched / IR pitched: No / No
Views / Downloads: 326 / 445
Version history: 5 change(s)
Referenced in: [show references]