Skip to content

Commit df88ce4

Browse files
committed
feat: extend TopicPartitionSession to inherit from EventEmitter and emit stop/end events
Signed-off-by: Vladislav Polyakov <[email protected]>
1 parent 99ac151 commit df88ce4

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/topic/src/partition-session.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
export class TopicPartitionSession {
1+
import { EventEmitter } from "node:stream"
2+
3+
type TopicPartitionSessionEmitterMap = {
4+
"stop": []
5+
"end": []
6+
}
7+
8+
export class TopicPartitionSession extends EventEmitter<TopicPartitionSessionEmitterMap> {
29
/**
310
* Partition session identifier.
411
*/
@@ -35,6 +42,8 @@ export class TopicPartitionSession {
3542
* @param topicPath - The path of the topic.
3643
*/
3744
constructor(partitionSessionId: bigint, partitionId: bigint, topicPath: string) {
45+
super();
46+
3847
this.partitionSessionId = partitionSessionId;
3948
this.partitionId = partitionId;
4049
this.topicPath = topicPath;
@@ -49,10 +58,12 @@ export class TopicPartitionSession {
4958
}
5059

5160
stop(): void {
61+
this.emit("stop");
5262
this.#stopped = true;
5363
}
5464

5565
end(): void {
66+
this.emit("end");
5667
this.#ended = true;
5768
}
5869
}

0 commit comments

Comments
 (0)