@sebspark/promise-cache 2.0.8 → 2.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -25,8 +25,7 @@ declare class Persistor {
25
25
  private onSuccess;
26
26
  private readonly redis?;
27
27
  constructor({ redis, clientId, onSuccess, onError, }: PersistorConstructorType);
28
- connect(): Promise<void>;
29
- startConnection(): Promise<unknown>;
28
+ startConnection(): Promise<void>;
30
29
  size(): Promise<number>;
31
30
  get<T>(key: string): Promise<GetType<T> | null>;
32
31
  getClientId(): UUID | undefined;
package/dist/index.d.ts CHANGED
@@ -25,8 +25,7 @@ declare class Persistor {
25
25
  private onSuccess;
26
26
  private readonly redis?;
27
27
  constructor({ redis, clientId, onSuccess, onError, }: PersistorConstructorType);
28
- connect(): Promise<void>;
29
- startConnection(): Promise<unknown>;
28
+ startConnection(): Promise<void>;
30
29
  size(): Promise<number>;
31
30
  get<T>(key: string): Promise<GetType<T> | null>;
32
31
  getClientId(): UUID | undefined;
package/dist/index.js CHANGED
@@ -98,35 +98,37 @@ var Persistor = class {
98
98
  CACHE_CLIENT = createLocalMemoryClient;
99
99
  }
100
100
  if (!this.client || !this.client.isReady) {
101
- this.connect();
101
+ this.startConnection();
102
102
  }
103
103
  }
104
- async connect() {
105
- await this.startConnection();
106
- }
107
- startConnection() {
108
- return new Promise((resolve, reject) => {
109
- this.client = CACHE_CLIENT({
110
- ...this.redis,
111
- socket: {
112
- reconnectStrategy: (retries, cause) => {
113
- console.error(cause);
114
- return 1e3 * 2 ** retries;
104
+ async startConnection() {
105
+ try {
106
+ await new Promise((resolve, reject) => {
107
+ this.client = CACHE_CLIENT({
108
+ ...this.redis,
109
+ socket: {
110
+ reconnectStrategy: (retries, cause) => {
111
+ console.error(cause);
112
+ return 1e3 * 2 ** retries;
113
+ }
115
114
  }
116
- }
117
- }).on("error", (err) => {
118
- this.onError(err);
119
- reject();
120
- }).on("ready", () => {
121
- this.onSuccess();
122
- resolve(true);
123
- }).on("reconnecting", () => {
124
- console.log("reconnecting...", this.clientId);
125
- }).on("end", () => {
126
- console.log("end...", this.clientId);
115
+ }).on("error", (err) => {
116
+ this.onError(err);
117
+ reject(err);
118
+ }).on("ready", () => {
119
+ this.onSuccess();
120
+ resolve(true);
121
+ }).on("reconnecting", () => {
122
+ console.log("reconnecting...", this.clientId);
123
+ }).on("end", () => {
124
+ console.log("end...", this.clientId);
125
+ });
126
+ this.client.connect();
127
127
  });
128
- return this.client.connect();
129
- });
128
+ } catch (ex) {
129
+ this.onError(`${ex}`);
130
+ console.error(ex);
131
+ }
130
132
  }
131
133
  async size() {
132
134
  if (!this.client) {
package/dist/index.mjs CHANGED
@@ -69,35 +69,37 @@ var Persistor = class {
69
69
  CACHE_CLIENT = createLocalMemoryClient;
70
70
  }
71
71
  if (!this.client || !this.client.isReady) {
72
- this.connect();
72
+ this.startConnection();
73
73
  }
74
74
  }
75
- async connect() {
76
- await this.startConnection();
77
- }
78
- startConnection() {
79
- return new Promise((resolve, reject) => {
80
- this.client = CACHE_CLIENT({
81
- ...this.redis,
82
- socket: {
83
- reconnectStrategy: (retries, cause) => {
84
- console.error(cause);
85
- return 1e3 * 2 ** retries;
75
+ async startConnection() {
76
+ try {
77
+ await new Promise((resolve, reject) => {
78
+ this.client = CACHE_CLIENT({
79
+ ...this.redis,
80
+ socket: {
81
+ reconnectStrategy: (retries, cause) => {
82
+ console.error(cause);
83
+ return 1e3 * 2 ** retries;
84
+ }
86
85
  }
87
- }
88
- }).on("error", (err) => {
89
- this.onError(err);
90
- reject();
91
- }).on("ready", () => {
92
- this.onSuccess();
93
- resolve(true);
94
- }).on("reconnecting", () => {
95
- console.log("reconnecting...", this.clientId);
96
- }).on("end", () => {
97
- console.log("end...", this.clientId);
86
+ }).on("error", (err) => {
87
+ this.onError(err);
88
+ reject(err);
89
+ }).on("ready", () => {
90
+ this.onSuccess();
91
+ resolve(true);
92
+ }).on("reconnecting", () => {
93
+ console.log("reconnecting...", this.clientId);
94
+ }).on("end", () => {
95
+ console.log("end...", this.clientId);
96
+ });
97
+ this.client.connect();
98
98
  });
99
- return this.client.connect();
100
- });
99
+ } catch (ex) {
100
+ this.onError(`${ex}`);
101
+ console.error(ex);
102
+ }
101
103
  }
102
104
  async size() {
103
105
  if (!this.client) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/promise-cache",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",