Skip to content

Commit 00c9850

Browse files
KamilKamil
authored andcommitted
enhancement(@nestjs/microservices) use isString helper instead
1 parent f86c0e3 commit 00c9850

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

packages/microservices/server/server.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { Logger } from '@nestjs/common/services/logger.service';
22
import { loadPackage } from '@nestjs/common/utils/load-package.util';
3-
import { isFunction } from '@nestjs/common/utils/shared.utils';
4-
import {
5-
EMPTY as empty,
6-
Observable,
7-
Subscription,
8-
from as fromPromise,
9-
of,
10-
} from 'rxjs';
3+
import { isFunction, isString } from '@nestjs/common/utils/shared.utils';
4+
import { EMPTY as empty, from as fromPromise, Observable, of, Subscription } from 'rxjs';
115
import { catchError, finalize } from 'rxjs/operators';
126
import { MessageHandlers } from '../interfaces/message-handlers.interface';
137
import { MicroserviceOptions, WritePacket } from './../interfaces';
@@ -16,6 +10,14 @@ export abstract class Server {
1610
protected readonly messageHandlers: MessageHandlers = {};
1711
protected readonly logger = new Logger(Server.name);
1812

13+
public addHandler(
14+
pattern: any,
15+
callback: (data) => Promise<Observable<any>>,
16+
) {
17+
const key = isString(pattern) ? pattern : JSON.stringify(pattern);
18+
this.messageHandlers[key] = callback;
19+
}
20+
1921
public getHandlers(): MessageHandlers {
2022
return this.messageHandlers;
2123
}
@@ -26,14 +28,6 @@ export abstract class Server {
2628
return this.messageHandlers[pattern] ? this.messageHandlers[pattern] : null;
2729
}
2830

29-
public addHandler(
30-
pattern: any,
31-
callback: (data) => Promise<Observable<any>>,
32-
) {
33-
const key = typeof pattern === 'string' ? pattern : JSON.stringify(pattern);
34-
this.messageHandlers[key] = callback;
35-
}
36-
3731
public send(
3832
stream$: Observable<any>,
3933
respond: (data: WritePacket) => void,

0 commit comments

Comments
 (0)