Skip to content

Commit

Permalink
fix: an error in checking a single channel will interrupt the entire …
Browse files Browse the repository at this point in the history
…check loop
  • Loading branch information
WhiteMinds committed Apr 9, 2024
1 parent d1ca1bd commit c3169c8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/manager/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ export function createRecorderManager<

let checkLoopTimer: NodeJS.Timeout | undefined

const multiThreadCheck = async () => {
const multiThreadCheck = async (manager: RecorderManager<ME, P, PE, E>) => {
// TODO: 先用写死的数量,后面改成可以设置的
const maxThreadCount = 3
// 这里暂时不打算用 state == recording 来过滤,provider 必须内部自己处理录制过程中的 check,
// 这样可以防止一些意外调用 checkLiveStatusAndRecord 时出现重复录制。
const needCheckRecorders = recorders.filter((r) => !r.disableAutoCheck)

const checkOnce = async () => {
const recorder = needCheckRecorders.pop()
const recorder = needCheckRecorders.shift()
if (recorder == null) return

await recorder.checkLiveStatusAndRecord({
Expand All @@ -119,7 +119,11 @@ export function createRecorderManager<

const threads = R.range(0, maxThreadCount).map(async () => {
while (needCheckRecorders.length > 0) {
await checkOnce()
try {
await checkOnce()
} catch (err) {
manager.emit('error', { source: 'checkOnceInThread', err })
}
}
})

Expand Down Expand Up @@ -171,7 +175,7 @@ export function createRecorderManager<

const checkLoop = async () => {
try {
await multiThreadCheck()
await multiThreadCheck(this)
} catch (err) {
this.emit('error', { source: 'multiThreadCheck', err })
} finally {
Expand Down

0 comments on commit c3169c8

Please sign in to comment.