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

31
LINES

< > BotCompany Repo | #1035117 // StepperWithStats

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

Libraryless. Click here for Pure Java version (9347L/52K).

srecord noeq StepperWithStats(Steppable steppable) > MetaWithChangeListeners is Steppable {
  settableWithVar new TimestampRange timeRange;
  settableWithVar long stepCount;
  settableWithVar bool done;
  
  public bool step() {
    if (done) false;
    if (steppable == null) false;
    
    ping();
    if (timeRange.start() == null) timeRange.startTime(tsNow());
    stepCount(stepCount+1);
    if (steppable.step()) true;
    
    // steppable ended
    timeRange.endTime(tsNow());
    done(true);
    false;
  }
  
  S renderStats() {
    S s = nSteps(stepCount);
    if (done) {
      s += " (done";
      if (timeRange.complete())
        s += " in " + formatSeconds(timeRange.duration(), 1) + "s";
      s += ")";
    }
    ret s;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035117
Snippet name: StepperWithStats
Eternal ID of this version: #1035117/5
Text MD5: 2f0a0f768034b4f8bfa4e1dc9e068619
Transpilation MD5: 8742a08b097dc89917551fc62981ad76
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-02 16:47:04
Source code size: 774 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 149 / 250
Version history: 4 change(s)
Referenced in: [show references]