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

29
LINES

< > BotCompany Repo | #1018973 // returnCodesOfServers_parallel_withTime

JavaX fragment (include)

static ItIt<T3<S, Int, Long>> returnCodesOfServers_parallel_withTime(int timeout, S... servers) {
  ret returnCodesOfServers_parallel_withTime(timeout, asList(servers));
}

static ItIt<T3<S, Int, Long>> returnCodesOfServers_parallel_withTime(final int timeout, final Collection<S> servers) {
  final Var<Int> counter = new(0);
  final L<T3<S, Int, Long>> results = synchroList();
  
  // Fire up the threads (with timeouts)
  
  for (fS server : servers)
    thread "Server Check" {
      long time = sysTime();
      int result = returnCodeHttpHEADWithTimeout(timeout, server);
      results.add(t3(server, result, sysNow()-time));
      syncIncIntVar(counter);
    }
    
  // Make iterator delivering results as they come in
  ret iteratorFromFunction(new F0<T3<S, Int, Long>>() {
    int n = 0;
    
    public T3<S, Int, Long> get() {
      if (n >= l(servers)) null;
      waitForVarToChange(counter, n);
      ret results.get(n++);
    }
  });
}

Author comment

Began life as a copy of #1018972

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1018973
Snippet name: returnCodesOfServers_parallel_withTime
Eternal ID of this version: #1018973/4
Text MD5: 86acf62699759ee09140c90d2332f21b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-18 16:53:51
Source code size: 982 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 343 / 353
Version history: 3 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)