smartdata/ts/smartdata.classes.watcher.ts

23 lines
583 B
TypeScript
Raw Normal View History

2022-05-16 22:33:44 +00:00
import * as plugins from './smartdata.plugins.js';
/**
* a wrapper for the native mongodb cursor. Exposes better
*/
export class SmartdataDbWatcher<T = any> {
// STATIC
// INSTANCE
public changeStream: plugins.mongodb.ChangeStream<T>;
public changeSubject = new plugins.smartrx.rxjs.Subject<T>();
constructor(changeStreamArg: plugins.mongodb.ChangeStream<T>) {
this.changeStream = changeStreamArg;
this.changeStream.on('change', (item: T) => {
this.changeSubject.next(item);
})
}
public async close() {
await this.changeStream.close();
}
}