@@ -11,35 +11,35 @@ xsenv.loadEnv(path.join(process.cwd(), "default-env.json"));
1111
1212const TIMEOUT = 5 * 1000 ;
1313
14- let mainClientPromise ;
15- let secondClientPromise ;
14+ let primaryClientPromise ;
15+ let secondaryClientPromise ;
1616
17- const createMainClientAndConnect = ( ) => {
18- if ( mainClientPromise ) {
19- return mainClientPromise ;
17+ const createPrimaryClientAndConnect = ( ) => {
18+ if ( primaryClientPromise ) {
19+ return primaryClientPromise ;
2020 }
2121
2222 const errorHandlerCreateClient = ( err ) => {
2323 LOG ?. error ( "Error from redis client for pub/sub failed" , err ) ;
24- mainClientPromise = null ;
25- setTimeout ( createMainClientAndConnect , TIMEOUT ) ;
24+ primaryClientPromise = null ;
25+ setTimeout ( createPrimaryClientAndConnect , TIMEOUT ) ;
2626 } ;
27- mainClientPromise = _createClientAndConnect ( errorHandlerCreateClient ) ;
28- return mainClientPromise ;
27+ primaryClientPromise = _createClientAndConnect ( errorHandlerCreateClient ) ;
28+ return primaryClientPromise ;
2929} ;
3030
31- const createSecondClientAndConnect = ( ) => {
32- if ( secondClientPromise ) {
33- return secondClientPromise ;
31+ const createSecondaryClientAndConnect = ( ) => {
32+ if ( secondaryClientPromise ) {
33+ return secondaryClientPromise ;
3434 }
3535
3636 const errorHandlerCreateClient = ( err ) => {
3737 LOG ?. error ( "Error from redis client for pub/sub failed" , err ) ;
38- secondClientPromise = null ;
39- setTimeout ( createSecondClientAndConnect , TIMEOUT ) ;
38+ secondaryClientPromise = null ;
39+ setTimeout ( createSecondaryClientAndConnect , TIMEOUT ) ;
4040 } ;
41- secondClientPromise = _createClientAndConnect ( errorHandlerCreateClient ) ;
42- return secondClientPromise ;
41+ secondaryClientPromise = _createClientAndConnect ( errorHandlerCreateClient ) ;
42+ return secondaryClientPromise ;
4343} ;
4444const _createClientBase = ( ) => {
4545 let credentials ;
@@ -94,7 +94,13 @@ const _createClientAndConnect = async (errorHandlerCreateClient) => {
9494 return client ;
9595} ;
9696
97+ const clearClients = ( ) => {
98+ primaryClientPromise = null ;
99+ secondaryClientPromise = null ;
100+ } ;
101+
97102module . exports = {
98- createMainClientAndConnect,
99- createSecondClientAndConnect,
103+ createPrimaryClientAndConnect,
104+ createSecondaryClientAndConnect,
105+ clearClients,
100106} ;
0 commit comments