Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout method to remote socket #4558

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion lib/broadcast-operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export class RemoteSocket<EmitEvents extends EventsMap, SocketData>
public readonly rooms: Set<Room>;
public readonly data: SocketData;

private readonly operator: BroadcastOperator<EmitEvents, SocketData>;
private operator: BroadcastOperator<EmitEvents, SocketData>;

constructor(adapter: Adapter, details: SocketDetails<SocketData>) {
this.id = details.id;
Expand All @@ -448,6 +448,25 @@ export class RemoteSocket<EmitEvents extends EventsMap, SocketData>
);
}

/**
* Adds a timeout in milliseconds for the next operation.
*
* @example
* socket.timeout(1000).emit("some-event", (err, responses) => {
* if (err) {
* // some clients did not acknowledge the event in the given delay
* } else {
* console.log(responses); // one response per client
* }
* });
*
* @param timeout
*/
public timeout(timeout: number) {
this.operator = this.operator.timeout(timeout);
return this;
}

public emit<Ev extends EventNames<EmitEvents>>(
ev: Ev,
...args: EventParams<EmitEvents, Ev>
Expand Down