牛队列的process方法返回的promise可以忽略不计吗?

Is it ok to ignore the promise returned by the process method of a bull queue?

我使用 bull 库来设置处理队列,当我对现有队列使用 process 方法时,我收到警告,因为此方法 return 是一个承诺.我注意到 bull 的文档忽略了这个 return 值,我想知道忽略这样的承诺是否安全。

其他小问题,这个功能失效了怎么办? 如果我需要等待它完成,这会导致问题,因为我必须到处等待结果,有没有办法避免这种情况?

https://github.com/OptimalBits/bull/issues/1688 (April 2020), committer manast answers Zikoel's question "Is not clear for me when the returned promise from Queue.process is resolved" with "in theory when the queue is closed." Because process starts the queue, as dprentis notes中,promise表示队列本身的状态。该问题从上周开始就有积极的团队参与,因此它可能与维护人员当前的理解或意图是准确的。

为方便起见,这里有一个link到Queue.process documentation。你是对的,它没有证明或承认 return Promise 来自对 process 的调用,尽管非常小心地规定了 [=14] 的 Promise return 要求=] 要传入的函数。

粗略地看一下代码(Queue.run), it seems that process specifically resolves when the closure of the queue resolves the promises (number set by concurrency, default 1) created as part of that single call to process. However, tests seem mostly to ignore the returned Promise or use it to chain catch to signal test completion; the few examples that use the returned promise seem to be suppressed 或其他例外情况。因为该行为似乎没有正式记录和测试,所以您可能不想过分依赖它。

尽管忽略 returned Promise(如在文档和测试中)或 await 其中任何一个来被动检测队列关闭似乎不是问题,但您还可以通过将所有 returned 承诺收集到 Promise.all 调用中并链接 catch 以记录任何错误来对冲您的赌注。