public void handle(Message<Integer> msg) {
sendBatch(msg, msg.body(), 10);
}
});
Regulator regulator=new Regulator<>();
Observable<RxStream<Integer,JsonArray>> res=rx.<Integer,JsonArray>observeStream("countdown", 4000)
// Add the regulator gate here
.lift(regulator)
// Process the stream
.map(new Func1<RxStream<Integer, JsonArray>, JsonArray>() {
public JsonArray call(RxStream<Integer, JsonArray> s) {
int start = s.value().get(0);
if (start > 0) {
s.next(start - 10);
}
return s.value();
}
})
.map(new Func1<JsonArray, Buffer>() {
public Buffer call(JsonArray data) {
return new Buffer(data.encode());
}
});
// Create a WriteStream that can only handle 5 writes per second
RatedWriteStream out=new RatedWriteStream(vertx,5);
assertCountThenComplete(regulator.stream(res,out),401);
}