@@ -3,7 +3,8 @@ import { Meteor } from 'meteor/meteor'
33import { MongoCursor } from '@sofie-automation/meteor-lib/dist/collections/lib'
44import { Simplify } from 'type-fest'
55import { assertNever } from '../../lib/tempLib'
6- import { waitForPromise } from '../../lib/lib'
6+ import { logger } from '../../logging'
7+ import { stringifyError } from '@sofie-automation/shared-lib/dist/lib/stringifyError'
78
89/**
910 * https://stackoverflow.com/a/66011942
@@ -41,18 +42,18 @@ export function observerChain(): Pick<Link<{}>, 'next'> {
4142 throw new Error ( 'nextChanged: Unfinished observer chain. This is a memory leak.' )
4243 }
4344
44- function changedLink ( collectorObject : Record < string , any > ) {
45+ async function changedLink ( collectorObject : Record < string , any > ) {
4546 if ( previousObserver ) {
4647 previousObserver . stop ( )
4748 previousObserver = null
4849 }
49- const cursorResult = waitForPromise ( chainedCursor ( collectorObject ) )
50+ const cursorResult = await chainedCursor ( collectorObject )
5051 if ( cursorResult === null ) {
5152 nextStop ( )
5253 return
5354 }
5455
55- previousObserver = cursorResult . observe ( {
56+ previousObserver = await cursorResult . observeAsync ( {
5657 added : ( doc ) => {
5758 if ( ! chainedKey ) throw new Error ( 'Chained key needs to be defined' )
5859 const newCollectorObject : Record < string , any > = {
@@ -96,10 +97,10 @@ export function observerChain(): Pick<Link<{}>, 'next'> {
9697 }
9798
9899 return {
99- changed : ( obj : Record < string , any > ) => {
100+ changed : async ( obj : Record < string , any > ) => {
100101 switch ( mode ) {
101102 case 'next' :
102- changedLink ( obj )
103+ await changedLink ( obj )
103104 break
104105 case 'end' :
105106 changedEnd ( obj )
@@ -160,7 +161,9 @@ export function observerChain(): Pick<Link<{}>, 'next'> {
160161 const nextLink = link . next ( key , cursorChain )
161162 setImmediate (
162163 Meteor . bindEnvironment ( ( ) => {
163- changed ( { } )
164+ changed ( { } ) . catch ( ( e ) => {
165+ logger . error ( `Error in observerChain: ${ stringifyError ( e ) } ` )
166+ } )
164167 } )
165168 )
166169 return nextLink as any
0 commit comments