@speckle/shared
Version:
Shared code between various Speckle JS packages
32 lines • 1.29 kB
JavaScript
import { ensureError } from '../core/helpers/error.js';
// MIT Licensed: https://github.com/OptimalBits/bull/blob/develop/LICENSE.md
// Reference: https://github.com/OptimalBits/bull/blob/develop/lib/utils.js
export const isRedisReady = (client) => {
return new Promise((resolve, reject) => {
if (client.status === 'ready') {
resolve();
}
else {
function handleReady() {
client.removeListener('end', handleEnd);
client.removeListener('error', handleError);
resolve();
}
function handleError(e) {
const err = ensureError(e, 'Unknown error in Redis client');
client.removeListener('ready', handleReady);
client.removeListener('error', handleError);
reject(err);
}
function handleEnd() {
client.removeListener('ready', handleReady);
client.removeListener('error', handleError);
reject(new Error('Redis connection ended'));
}
client.once('ready', handleReady);
client.on('error', handleError);
client.once('end', handleEnd);
}
});
};
//# sourceMappingURL=isRedisReady.js.map