-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hopefully. Now only missing the RabbitConnection.
- Loading branch information
1 parent
3d757dd
commit ed1dcf6
Showing
5 changed files
with
154 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
export * from "./CommonConfig.js"; | ||
|
||
export * from "./broker/BrokerClient.js"; | ||
export * from "./broker/BrokerMessage.js"; | ||
export * from "./broker/BrokerConnection.js"; | ||
export * from "./broker/BrokerMessage.js"; | ||
export * from "./broker/BrokerMessageHeaders.js"; | ||
export * from "./broker/kafka/KafkaConnection.js"; | ||
export * from "./broker/kafka/KafkaMessageHeaders.js"; | ||
export * from "./broker/Exceptions.js"; | ||
export * from "./broker/LocalConnection.js"; | ||
export * from "./broker/Subclients.js"; | ||
export * from "./broker/rpc/RpcClient.js"; | ||
export * from "./broker/rpc/RpcMessage.js"; | ||
export * from "./broker/rpc/RpcMessageHeaders.js"; | ||
export * from "./broker/rpc/RpcStatus.js"; | ||
|
||
export * from "./logging/Logger.js"; | ||
|
||
export * from "./util/CountDownLatch.js"; | ||
export * from "./util/OnlineEmitter.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
export class OnlineEmitter<T> { | ||
|
||
private readonly listeners: Set<(data: T) => void> = new Set(); | ||
|
||
public emit(data: T): void { | ||
for (const listener of this.listeners) { | ||
listener(data); | ||
} | ||
} | ||
|
||
public addListener(listener: (data: T) => void): void { | ||
this.listeners.add(listener); | ||
} | ||
|
||
|
||
public removeListener(listener: (data: T) => void): void { | ||
this.listeners.delete(listener); | ||
} | ||
|
||
public async awaitValue(): Promise<T> { | ||
return new Promise(resolve => { | ||
const listener = (data: T) => { | ||
this.removeListener(listener); | ||
resolve(data); | ||
}; | ||
this.addListener(listener); | ||
}); | ||
} | ||
|
||
public [Symbol.asyncIterator](): AsyncIterableIterator<T> { | ||
const awaitValue = this.awaitValue.bind(this); | ||
return { | ||
async next(): Promise<IteratorResult<T>> { | ||
const value = await awaitValue(); | ||
return { value, done: false }; | ||
}, | ||
[Symbol.asyncIterator](): AsyncIterableIterator<T> { | ||
return this; | ||
}, | ||
}; | ||
} | ||
|
||
} |