下一个JS页/API;很难从API致电ImpruxDB客户端
我在NextJS页面/API文件夹中写了一个处理程序功能;
handler(req, res) {}
如文档中所述,我正在使用 @infuxdata/infuxdb-client。 一旦可观察到完成后,我正在使用
from(queryAPI.rows(query).pipe(....).subscribe(next(value)=> {results.push(value}, complete(console.log(results); res.status(200).json(results)}
所有查询值。它在大多数时候起作用。
正在推动订户的下一部分中的中间结果,并试图将结果发送回订户的完整部分。我希望请求处理程序能等到我从订户的完整部分中从涌入DB查询中获取所有值,并可以将值发送回客户端。
但是“处理程序功能不会等到可观察到可观察到完成”。在观察者完成之前,处理程序功能返回。正在发生错误: API在未发送响应的情况下解决了 ...
我仅在观察者完成时才能获得所有值。 我不知道如何处理这种情况。
如何使处理程序功能等到可观察到完成?
I have written a handler function inside my nextjs page/api folder;
handler(req, res) {}
Am using @influxdata/influxDb-client as mentioned in the documentation. Am using
from(queryAPI.rows(query).pipe(....).subscribe(next(value)=> {results.push(value}, complete(console.log(results); res.status(200).json(results)}
Am getting all the query value, once the observable is completed. it works most of the time.
Am pushing the intermediate results in the next part of the subscriber and trying to send the results back to client in the complete part of the subscriber. I want the request handler to wait till i get all my values from influx DB query in the complete part of the subscriber and can send the value back to client..
But the issue "Handler function will not Wait till the observable is completed". Handler function returns, before the observer gets completed. Am getting error: API resolved without sending a response...
I get all the values only when the observer is completed.
I don't know how to handle the scenario.
How can I make the handler function wait until the observable is completed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案的解决方案,
我使用了新的Promise()等待,在这个诺言中添加了我可观察的可观察到的, 解决了订阅的诺言。
代码看起来如下:
I found the solution for the same
I used new Promise() with await, added my observable inside this promise and resolved the promise on Complete of the subscribe.
Code will look like the following :