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]

Transpiled version (2624L) is out of date.

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

Author comment

Began life as a copy of #1015681

download  show line numbers  debug dex   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, 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
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: 102 / 153
Version history: 5 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1024356 & http://1024356.tinybrain.de