问题描述
在将文件上传到 firebase 后,我创建了对侦听 GCP 触发器日志的递归调用,这基本上运行良好。
我的问题,我的递归扩展函数永远不会退出。
从代码中可以看出,我已经不止一次检查了值,似乎一切都很好,我也在控制台日志中看到了 DECLARE @temp_table TABLE(
category_id INT IDENTITY(1,1),category_name VARCHAR(100)
)
INSERT INTO @temp_table
SELECT disTINCT category.category_name
FROM category
SELECT *
FROM @temp_table
LEFT JOIN (
SELECT SUM(year_total) 'total',cat_a_id
FROM fin_transactions
GROUP BY cat_a_id
) AS table_1
ON table_1.cat_a_id = @temp_table.category_id
消息,但是递归调用永远不会完成,没有任何错误。
如果条件为真,如果我想中断或强制中断递归调用,我该怎么办?
ENTERED
在我调用 getlog 的地方,(您可以看到我检查了快照更改以仅触发一次 getlog,上传完成后,我对其进行了调试,没问题),因此 {{1} } 从未被触发,因为 getlog 中的无限递归循环。
public getLog(filePath: string): Observable<object[]> {
try {
...
return this.getLogChunk()
.pipe(
expand((data: any) => {
if (!environment.production && data && data.entries && data.entries.length > 0) {
console.groupCollapsed('GCP Service Info [getLog]');
console.info('[fileName]',fileName);
console.info('[some - Finished]',data.entries.some((x: any) => x.textPayload.includes('Finished')));
console.info('[some - Filename]',data.entries.some((x: any) => x.textPayload.includes(fileName)));
console.info('[some - Finished - Filename]',data.entries.some((x: any) => x.textPayload.includes('Finished') && x.textPayload.includes(fileName)));
console.info('[filter - Filename]',data.entries.filter((x: any) => x.textPayload.includes(fileName)));
console.groupEnd();
}
if (data &&
data.entries &&
data.entries.some((x: any) => x.textPayload.includes('Finished') && x.textPayload.includes(fileName))) {
console.log('ENTERED!!!!!');
return of({});
}
return this.getLogChunk().pipe(delay(2000));
}),map(res => res),reduce((acc: object[],val: any) => acc.concat(val),new Array<object>())
)
}
return new Observable<object[]>();
} catch (e) {
if (!environment.production) {
console.groupCollapsed('GCP Service Error [getLog]');
console.error('[error]',e);
console.groupEnd();
}
throw new Error(e);
}
}
解决方法
我发现问题在于 return of({})
调用 - 这也会扩展,因为它提供了一个值。如果您希望扩展结束,请改为调用 return EMPTY
(从 'Rxjs' 导入)。 EMTPY
不返回值并立即完成,因此 expand 不会继续侦听。