RXJS TAP操作员支持异步函数?

发布于 2025-02-11 07:31:39 字数 375 浏览 1 评论 0原文

我的示例代码是

    this.urls$.pipe(
      map(async (val) => {
        return await http.get(url);
      }),
      tap(async (val) => {
        const res = await val.res;
        console.log(res);
        return ture;
      })
    ).subscribe();

,但我收到了一条ESLINT消息。

预期返回空隙。

在函数辩论中返回的承诺,可以

my example code is

    this.urls$.pipe(
      map(async (val) => {
        return await http.get(url);
      }),
      tap(async (val) => {
        const res = await val.res;
        console.log(res);
        return ture;
      })
    ).subscribe();

but i got a eslint message.

Promise returned in function argument where a void return was expected.eslint

how can i avoid this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潜移默化 2025-02-18 07:31:39

您可以将承诺转换为可观察的,并使用switchmap(或simelar)运算符,而不是等待地图中的承诺。

this.urls$.pipe(
      switchMap((val) => from(http.get(url))),
      tap((val) => console.log(val.res)),
    ).subscribe();

Instead of awaiting a promise within map, you could convert the promise to an observable and use switchMap (or simelar) operator.

this.urls$.pipe(
      switchMap((val) => from(http.get(url))),
      tap((val) => console.log(val.res)),
    ).subscribe();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文