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

20
LINES

< > BotCompany Repo | #1001746 // updateLoop - requires a function called "update"

JavaX fragment (include)

  static int updateLoop_defaultInterval = 5000;
  
  static void updateLoop(int interval) {
    updateLoop_defaultInterval = interval;
    updateLoop();
  }
  
  static void updateLoop() {
    thread "update loop" {
      while (true) {
        try {
          update();
        } catch (Throwable e) {
          e.printStackTrace();
        }
        Integer interval = cast getOpt(getMainClass(), "updateInterval");
        sleep(interval == null || interval == 0 ? updateLoop_defaultInterval : interval);
      }
    }
  }

Author comment

Optionally uses a variable called "updateInterval". Default is 5000 ms.

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: #1001746
Snippet name: updateLoop - requires a function called "update"
Eternal ID of this version: #1001746/1
Text MD5: 58575237eb63cdbda6c7296280570e9d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-11-12 21:47:00
Source code size: 544 bytes / 20 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 653 / 1101
Referenced in: #1001760 - Quick Talk Window (talk to bot selected in swing-top 2, no actual functionality yet)
#1002427 - Accellerating 629 (SPIKE)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#3000382 - Answer for ferdie (>> t = 1, f = 0)