Skip to content

Commit ecacb90

Browse files
committed
wip: fix another waitForPromise
1 parent 97c19b6 commit ecacb90

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

meteor/server/api/ingest/rundownInput.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -429,19 +429,19 @@ async function onMediaObjectChanged(newDocument: MediaObject, oldDocument?: Medi
429429

430430
for (const mediaObjectUpdatedIds of updateIds) {
431431
if (validSegmentIds.has(mediaObjectUpdatedIds.segmentId)) {
432-
try {
433-
lazyIgnore(
434-
`updateSegmentFromMediaObject_${mediaObjectUpdatedIds.segmentId}`,
435-
async () => updateSegmentFromCache(newDocument.studioId, mediaObjectUpdatedIds),
436-
200
437-
)
438-
} catch (exception) {
439-
logger.error(
440-
`Error thrown while updating Segment from cache after MediaObject changed: ${stringifyError(
441-
exception
442-
)}`
443-
)
444-
}
432+
lazyIgnore(
433+
`updateSegmentFromMediaObject_${mediaObjectUpdatedIds.segmentId}`,
434+
() => {
435+
updateSegmentFromCache(newDocument.studioId, mediaObjectUpdatedIds).catch((e) => {
436+
logger.error(
437+
`Error thrown while updating Segment from cache after MediaObject changed: ${stringifyError(
438+
e
439+
)}`
440+
)
441+
})
442+
},
443+
200
444+
)
445445
}
446446
}
447447
}

meteor/server/lib/lib.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function MeteorWrapAsync(func: Function, context?: Object): any {
5757
}
5858

5959
const lazyIgnoreCache: { [name: string]: number } = {}
60-
export function lazyIgnore(name: string, f1: () => Promise<void> | void, t: number): void {
60+
export function lazyIgnore(name: string, f1: () => void, t: number): void {
6161
// Don't execute the function f1 until the time t has passed.
6262
// Subsequent calls will extend the laziness and ignore the previous call
6363

@@ -66,12 +66,11 @@ export function lazyIgnore(name: string, f1: () => Promise<void> | void, t: numb
6666
}
6767
lazyIgnoreCache[name] = Meteor.setTimeout(() => {
6868
delete lazyIgnoreCache[name]
69-
if (Meteor.isClient) {
70-
f1()?.catch((e) => {
71-
throw new Error(e)
72-
})
73-
} else {
74-
waitForPromise(f1())
69+
70+
try {
71+
f1()
72+
} catch (e) {
73+
logger.error(`Unhandled error in lazyIgnore "${name}": ${stringifyError(e)}`)
7574
}
7675
}, t)
7776
}

meteor/server/publications/lib/observerChain.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { Meteor } from 'meteor/meteor'
33
import { MongoCursor } from '@sofie-automation/meteor-lib/dist/collections/lib'
44
import { Simplify } from 'type-fest'
55
import { 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

Comments
 (0)