mirror of
https://github.com/aljazceru/ditto.git
synced 2025-12-28 10:44:27 +01:00
Refactor streaming to use async iterators
This commit is contained in:
@@ -63,11 +63,9 @@ function connectStream(socket: WebSocket) {
|
||||
|
||||
send(['EOSE', subId]);
|
||||
|
||||
Sub.sub({
|
||||
id: subId,
|
||||
filters: prepared,
|
||||
socket,
|
||||
});
|
||||
for await (const event of Sub.sub(socket, subId, prepared)) {
|
||||
send(['EVENT', subId, event]);
|
||||
}
|
||||
}
|
||||
|
||||
/** Handle EVENT. Store the event. */
|
||||
@@ -87,7 +85,7 @@ function connectStream(socket: WebSocket) {
|
||||
|
||||
/** Handle CLOSE. Close the subscription. */
|
||||
function handleClose([_, subId]: ClientCLOSE): void {
|
||||
Sub.unsub({ id: subId, socket });
|
||||
Sub.unsub(socket, subId);
|
||||
}
|
||||
|
||||
/** Send a message back to the client. */
|
||||
|
||||
Reference in New Issue
Block a user