1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | function isSentinelEql(a, b) {
|
4 | return ((a.host || "127.0.0.1") === (b.host || "127.0.0.1") &&
|
5 | (a.port || 26379) === (b.port || 26379));
|
6 | }
|
7 | class SentinelIterator {
|
8 | constructor(sentinels) {
|
9 | this.cursor = 0;
|
10 | this.sentinels = sentinels.slice(0);
|
11 | }
|
12 | next() {
|
13 | const done = this.cursor >= this.sentinels.length;
|
14 | return { done, value: done ? undefined : this.sentinels[this.cursor++] };
|
15 | }
|
16 | reset(moveCurrentEndpointToFirst) {
|
17 | if (moveCurrentEndpointToFirst &&
|
18 | this.sentinels.length > 1 &&
|
19 | this.cursor !== 1) {
|
20 | this.sentinels.unshift(...this.sentinels.splice(this.cursor - 1));
|
21 | }
|
22 | this.cursor = 0;
|
23 | }
|
24 | add(sentinel) {
|
25 | for (let i = 0; i < this.sentinels.length; i++) {
|
26 | if (isSentinelEql(sentinel, this.sentinels[i])) {
|
27 | return false;
|
28 | }
|
29 | }
|
30 | this.sentinels.push(sentinel);
|
31 | return true;
|
32 | }
|
33 | toString() {
|
34 | return `${JSON.stringify(this.sentinels)} @${this.cursor}`;
|
35 | }
|
36 | }
|
37 | exports.default = SentinelIterator;
|