2021-05-19 15:25:07 -04:00
|
|
|
/* eslint-disable
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2021-05-19 15:25:07 -04:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
let listenInBackground, sendPings;
|
|
|
|
const redis = require("@overleaf/redis-wrapper");
|
|
|
|
const rclient1 = redis.createClient({cluster: [{
|
|
|
|
port: "7000",
|
2017-05-04 06:14:17 -04:00
|
|
|
host: "localhost"
|
2021-05-19 15:25:07 -04:00
|
|
|
}]});
|
2017-05-04 06:14:17 -04:00
|
|
|
|
2021-05-19 15:25:07 -04:00
|
|
|
const rclient2 = redis.createClient({cluster: [{
|
|
|
|
port: "7000",
|
2017-05-04 06:14:17 -04:00
|
|
|
host: "localhost"
|
2021-05-19 15:25:07 -04:00
|
|
|
}]});
|
2017-05-04 06:14:17 -04:00
|
|
|
|
2021-05-19 15:25:07 -04:00
|
|
|
let counter = 0;
|
|
|
|
const sendPing = function(cb) {
|
|
|
|
if (cb == null) { cb = function() {}; }
|
2021-05-19 15:25:07 -04:00
|
|
|
return rclient1.rpush("test-blpop", counter, (error) => {
|
2021-05-19 15:25:07 -04:00
|
|
|
if (error != null) { console.error("[SENDING ERROR]", error.message); }
|
|
|
|
if ((error == null)) {
|
|
|
|
counter += 1;
|
|
|
|
}
|
|
|
|
return cb();
|
|
|
|
});
|
|
|
|
};
|
2017-05-04 06:14:17 -04:00
|
|
|
|
2021-05-19 15:25:07 -04:00
|
|
|
let previous = null;
|
2021-05-19 15:25:07 -04:00
|
|
|
const listenForPing = cb => rclient2.blpop("test-blpop", 200, (error, result) => {
|
2021-05-19 15:25:07 -04:00
|
|
|
if (error != null) { return cb(error); }
|
|
|
|
let [key, value] = Array.from(result);
|
|
|
|
value = parseInt(value, 10);
|
|
|
|
if ((value % 10) === 0) {
|
|
|
|
console.log(".");
|
|
|
|
}
|
|
|
|
if ((previous != null) && (value !== (previous + 1))) {
|
|
|
|
error = new Error(`Counter not in order. Got ${value}, expected ${previous + 1}`);
|
|
|
|
}
|
|
|
|
previous = value;
|
|
|
|
return cb(error, value);
|
|
|
|
});
|
2017-05-04 06:14:17 -04:00
|
|
|
|
2021-05-19 15:25:07 -04:00
|
|
|
const PING_DELAY = 100;
|
|
|
|
(sendPings = () => sendPing(() => setTimeout(sendPings, PING_DELAY)))();
|
2017-05-04 06:14:17 -04:00
|
|
|
|
2021-05-19 15:25:07 -04:00
|
|
|
(listenInBackground = () => listenForPing((error, value) => {
|
2021-05-19 15:25:07 -04:00
|
|
|
if (error) { console.error("[RECEIVING ERROR]", error.message); }
|
|
|
|
return setTimeout(listenInBackground);
|
|
|
|
}))();
|