提交 db3ea4fc authored 作者: a's avatar a

fix(connection): disconnect sync

eliminate onModuleDestroy async flow since client.disconnect() is sync
上级 40c27c0c
......@@ -7,5 +7,5 @@ export declare class RedisCoreModule implements OnModuleDestroy {
constructor(options: RedisModuleOptions | RedisModuleOptions[], moduleRef: ModuleRef);
static register(options: RedisModuleOptions | RedisModuleOptions[]): DynamicModule;
static forRootAsync(options: RedisModuleAsyncOptions): DynamicModule;
onModuleDestroy(): Promise<void>;
onModuleDestroy(): void;
}
......@@ -11,14 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
var RedisCoreModule_1;
const common_1 = require("@nestjs/common");
......@@ -50,23 +42,21 @@ let RedisCoreModule = RedisCoreModule_1 = class RedisCoreModule {
};
}
onModuleDestroy() {
return __awaiter(this, void 0, void 0, function* () {
const closeConnection = ({ clients, defaultKey }) => (options) => __awaiter(this, void 0, void 0, function* () {
const name = options.name || defaultKey;
const client = clients.get(name);
if (client && !options.keepAlive) {
yield client.disconnect();
}
});
const redisClient = this.moduleRef.get(redis_constants_1.REDIS_CLIENT);
const closeClientConnection = closeConnection(redisClient);
if (Array.isArray(this.options)) {
yield Promise.all(this.options.map(closeClientConnection));
}
else {
yield closeClientConnection(this.options);
const closeConnection = ({ clients, defaultKey }) => options => {
const name = options.name || defaultKey;
const client = clients.get(name);
if (client && !options.keepAlive) {
client.disconnect();
}
});
};
const redisClient = this.moduleRef.get(redis_constants_1.REDIS_CLIENT);
const closeClientConnection = closeConnection(redisClient);
if (Array.isArray(this.options)) {
this.options.forEach(closeClientConnection);
}
else {
closeClientConnection(this.options);
}
}
};
RedisCoreModule = RedisCoreModule_1 = __decorate([
......
......@@ -50,13 +50,13 @@ export class RedisCoreModule implements OnModuleDestroy {
};
}
async onModuleDestroy() {
const closeConnection = ({ clients, defaultKey }) => async options => {
onModuleDestroy() {
const closeConnection = ({ clients, defaultKey }) => options => {
const name = options.name || defaultKey;
const client = clients.get(name);
if (client && !options.keepAlive) {
await client.disconnect();
client.disconnect();
}
};
......@@ -64,9 +64,9 @@ export class RedisCoreModule implements OnModuleDestroy {
const closeClientConnection = closeConnection(redisClient);
if (Array.isArray(this.options)) {
await Promise.all(this.options.map(closeClientConnection));
this.options.forEach(closeClientConnection);
} else {
await closeClientConnection(this.options);
closeClientConnection(this.options);
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论