chore: use descriptive type parameter names (#9937)

* chore: use descriptive type parameter names

* refactor: requested changes

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Almeida
2023-11-12 17:21:51 +00:00
committed by GitHub
parent 4ff3ea4a1b
commit 975d5f18ae
34 changed files with 1104 additions and 895 deletions

View File

@@ -75,7 +75,7 @@ export interface IPubSubBroker<TEvents extends Record<string, any>>
/**
* Publishes an event
*/
publish<T extends keyof TEvents>(event: T, data: TEvents[T]): Promise<void>;
publish<Event extends keyof TEvents>(event: Event, data: TEvents[Event]): Promise<void>;
}
export interface IRPCBroker<TEvents extends Record<string, any>, TResponses extends Record<keyof TEvents, any>>
@@ -84,5 +84,9 @@ export interface IRPCBroker<TEvents extends Record<string, any>, TResponses exte
/**
* Makes an RPC call
*/
call<T extends keyof TEvents>(event: T, data: TEvents[T], timeoutDuration?: number): Promise<TResponses[T]>;
call<Event extends keyof TEvents>(
event: Event,
data: TEvents[Event],
timeoutDuration?: number,
): Promise<TResponses[Event]>;
}

View File

@@ -36,7 +36,7 @@ export class PubSubRedisBroker<TEvents extends Record<string, any>>
/**
* {@inheritDoc IPubSubBroker.publish}
*/
public async publish<T extends keyof TEvents>(event: T, data: TEvents[T]): Promise<void> {
public async publish<Event extends keyof TEvents>(event: Event, data: TEvents[Event]): Promise<void> {
await this.options.redisClient.xadd(
event as string,
'*',

View File

@@ -83,11 +83,11 @@ export class RPCRedisBroker<TEvents extends Record<string, any>, TResponses exte
/**
* {@inheritDoc IRPCBroker.call}
*/
public async call<T extends keyof TEvents>(
event: T,
data: TEvents[T],
public async call<Event extends keyof TEvents>(
event: Event,
data: TEvents[Event],
timeoutDuration: number = this.options.timeout,
): Promise<TResponses[T]> {
): Promise<TResponses[Event]> {
const id = await this.options.redisClient.xadd(
event as string,
'*',
@@ -103,7 +103,7 @@ export class RPCRedisBroker<TEvents extends Record<string, any>, TResponses exte
const timedOut = new Error(`timed out after ${timeoutDuration}ms`);
await this.streamReadClient.subscribe(rpcChannel);
return new Promise<TResponses[T]>((resolve, reject) => {
return new Promise<TResponses[Event]>((resolve, reject) => {
const timeout = setTimeout(() => reject(timedOut), timeoutDuration).unref();
this.promises.set(id!, { resolve, reject, timeout });