Skip to content

Commit

Permalink
Some improvements in searchTermsSseController
Browse files Browse the repository at this point in the history
  • Loading branch information
mapeveri committed Jan 3, 2024
1 parent 967480d commit a84927b
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import SearchTermQuery from '@src/languages/application/term/query/search/search

@Controller('sse')
export class SearchTermsSseController {
private EVENT_NAME = 'terms';

constructor(@Inject(QUERY_BUS) private queryBus: QueryBus) {}

@Sse('terms/:userId/:term')
Expand All @@ -14,15 +16,15 @@ export class SearchTermsSseController {

const intervalId = setInterval(async () => {
const data = await this.queryBus.ask(new SearchTermQuery(term));
const event = new MessageEvent('terms', { data: JSON.stringify(data.content) });
const event = new MessageEvent(this.EVENT_NAME, { data: JSON.stringify(data.content) });

observer.next(event);
}, 5000);

subscription.add(() => {
clearInterval(intervalId);
subscription.unsubscribe();
});
subscription.add(() => subscription.unsubscribe());

return subscription;
});
Expand Down

0 comments on commit a84927b

Please sign in to comment.