Refactor streaming to use async iterators

This commit is contained in:
Alex Gleason
2023-08-25 13:35:20 -05:00
parent 00c531bbff
commit baace5ea2d
4 changed files with 85 additions and 38 deletions

View File

@@ -93,8 +93,8 @@ const isFresh = ({ created_at }: Event): boolean => created_at >= nostrNow() - T
function streamOut(event: Event, data: EventData) {
if (!isFresh(event)) return;
for (const { socket, id } of Sub.matches(event, data)) {
socket.send(JSON.stringify(['EVENT', id, event]));
for (const sub of Sub.matches(event, data)) {
sub.stream(event);
}
}