Source:
public Iterator<GHThread> iterator() { final Requester req = root.retrieve() .method("GET") .with("all", all) .with("participating", participating) .with("since", since); return new Iterator<GHThread>() { private GHThread[] threads = EMPTY_ARRAY; private int idx = -1; private long lastUpdated = -1; private String lastModified; private long nextCheckTime = -1; private GHThread next; public GHThread next() { if (next == null) { next = fetch(); if (next == null) throw new NoSuchElementException(); } GHThread r = next; next = null; return r; } public boolean hasNext() { if (next == null) next = fetch(); return next != null; } GHThread fetch() { try { while (true) { while (idx >= 0) { GHThread n = threads[idx--]; long nt = n.getUpdatedAt().getTime(); if (nt >= lastUpdated) { lastUpdated = nt; return n.wrap(root); } } if (nonBlocking && nextCheckTime >= 0) return null; while (true) { long now = System.currentTimeMillis(); if (nextCheckTime < now) break; long waitTime = Math.min(Math.max(nextCheckTime - now, 1000), 60 * 1000); Thread.sleep(waitTime); } req.setHeader("If-Modified-Since", lastModified); threads = req.withUrlPath(apiUrl).toArray(GHThread[].class); if (threads == null) { threads = EMPTY_ARRAY; } else { lastUpdated++; } idx = threads.length - 1; nextCheckTime = calcNextCheckTime(); lastModified = req.getResponseHeader("Last-Modified"); } } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } } private long calcNextCheckTime() { String v = req.getResponseHeader("X-Poll-Interval"); if (v == null) v = "60"; long seconds = Integer.parseInt(v); return System.currentTimeMillis() + seconds * 1000; } public void remove() { throw new UnsupportedOperationException(); } }; }

Target:
public Iterator<GHThread> iterator() { final Requester req = root.createRequest() .with("all", all) .with("participating", participating) .with("since", since); return new Iterator<GHThread>() { private GHThread[] threads = EMPTY_ARRAY; private int idx = -1; private long lastUpdated = -1; private String lastModified; private long nextCheckTime = -1; private GHThread next; public GHThread next() { if (next == null) { next = fetch(); if (next == null) throw new NoSuchElementException(); } GHThread r = next; next = null; return r; } public boolean hasNext() { if (next == null) next = fetch(); return next != null; } GHThread fetch() { try { while (true) { while (idx >= 0) { GHThread n = threads[idx--]; long nt = n.getUpdatedAt().getTime(); if (nt >= lastUpdated) { lastUpdated = nt; return n.wrap(root); } } if (nonBlocking && nextCheckTime >= 0) return null; while (true) { long now = System.currentTimeMillis(); if (nextCheckTime < now) break; long waitTime = Math.min(Math.max(nextCheckTime - now, 1000), 60 * 1000); Thread.sleep(waitTime); } req.setHeader("If-Modified-Since", lastModified); threads = req.withUrlPath(apiUrl).fetchArray(GHThread[].class); if (threads == null) { threads = EMPTY_ARRAY; } else { lastUpdated++; } idx = threads.length - 1; nextCheckTime = calcNextCheckTime(); lastModified = req.getResponseHeader("Last-Modified"); } } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } } private long calcNextCheckTime() { String v = req.getResponseHeader("X-Poll-Interval"); if (v == null) v = "60"; long seconds = Integer.parseInt(v); return System.currentTimeMillis() + seconds * 1000; } public void remove() { throw new UnsupportedOperationException(); } }; }