private void runTimeouts(List<TimeoutInfo> timeouts, HttpServerResponse response) { Iterator<TimeoutInfo> iter = timeouts.iterator(); nextTimeout(timeouts, iter, response); }
public void handle(RoutingContext rc) { rc.response().headers().set("Content-Type", "application/javascript; charset=UTF-8"); BaseTransport.setCORS(rc); rc.response().setChunked(true); Buffer h = buffer(2); h.appendString("h\n"); Buffer hs = buffer(2050); for (int i = 0; i < 2048; i++) { hs.appendByte((byte) ' '); } hs.appendString("h\n"); List<TimeoutInfo> timeouts = new ArrayList<>(); setTimeout(timeouts, 0, h); setTimeout(timeouts, 1, hs); setTimeout(timeouts, 5, h); setTimeout(timeouts, 25, h); setTimeout(timeouts, 125, h); setTimeout(timeouts, 625, h); setTimeout(timeouts, 3125, h); runTimeouts(timeouts, rc.response()); } };
private void runTimeouts(List<TimeoutInfo> timeouts, HttpServerResponse response) { Iterator<TimeoutInfo> iter = timeouts.iterator(); nextTimeout(timeouts, iter, response); }
private void nextTimeout(List<TimeoutInfo> timeouts, Iterator<TimeoutInfo> iter, HttpServerResponse response) { if (iter.hasNext()) { TimeoutInfo timeout = iter.next(); vertx.setTimer(timeout.timeout, id -> { response.write(timeout.buff); nextTimeout(timeouts, iter, response); }); } else { timeouts.clear(); } }
public void handle(RoutingContext rc) { rc.response().headers().set("Content-Type", "application/javascript; charset=UTF-8"); BaseTransport.setCORS(rc); rc.response().setChunked(true); Buffer h = buffer(2); h.appendString("h\n"); Buffer hs = buffer(2050); for (int i = 0; i < 2048; i++) { hs.appendByte((byte) ' '); } hs.appendString("h\n"); List<TimeoutInfo> timeouts = new ArrayList<>(); setTimeout(timeouts, 0, h); setTimeout(timeouts, 1, hs); setTimeout(timeouts, 5, h); setTimeout(timeouts, 25, h); setTimeout(timeouts, 125, h); setTimeout(timeouts, 625, h); setTimeout(timeouts, 3125, h); runTimeouts(timeouts, rc.response()); } };
private void nextTimeout(List<TimeoutInfo> timeouts, Iterator<TimeoutInfo> iter, HttpServerResponse response) { if (iter.hasNext()) { TimeoutInfo timeout = iter.next(); vertx.setTimer(timeout.timeout, id -> { response.write(timeout.buff); nextTimeout(timeouts, iter, response); }); } else { timeouts.clear(); } }