Hello
Is it possible to use setInterval in a projection?
class BulkBooksBuffer {
static init(s, e) {
return {
count: 0,
books: [],
sequence: 1,
metadata: {
EventClrType: ‘Library.BooksReadyEvent, Library’,
UserName: ‘’,
AuthenticationType: ‘’
}
};
}
static onBulkBookFinishedEvent(s, e) {
s.books.push(e.data.streamId);
s.count += 1;
**if (s.count == 10) {**
if (s.count > 0) {
emit('Bulk-Books-Ready',
'BulkBooksReadyEvent',
{ Books: s.books, Sequence: s.sequence },
s.metadata);
s.count = 0;
s.books = [];
s.sequence += 1;
}
}
}
}
fromStream(‘Bulk-Books’)
.when({
$init: BulkBooksBuffer.init,
BulkBookFinishedEvent: BulkBooksBuffer.onBulkBookFinishedEvent
});
In the above code, I would like to emit an event if count is equal to 10 or after 5 seconds. Whichever comes first.
Where can I write the setInterval function?
Many thanks.