【问题标题】:RXJS to synchronise a network callRXJS 同步网络调用
【发布时间】:2020-02-27 03:07:45
【问题描述】:

我们的 ionic 应用程序频繁调用特定的 Web 服务,当并行进行相同的调用时,服务器会抛出错误。

我们要确保调用是同步的。如何在 RXJS 中实现这一点?

Observers(View1..n)=>Observable(User)=={apply control here?}==>NetworkCall(getUser())

【问题讨论】:

  • .concatMap 将确保所有请求都是连续的

标签: node.js angular ionic-framework rxjs


【解决方案1】:

使用 concat Map 进行顺序调用

concatMap():将每个源值投影到一个 Observable,该 Observable 合并到输出 Observable 中,以序列化的方式等待每个源值完成,然后再合并下一个

SendMsg(msgs: string[]) {

            msgs.map(msg=> this.SendMsgService.({setail: msg.description, userId: msguser}));
            from(msgCalls)  
                .pipe(
                    concatMap(res => res), 
                ).subscribe(() => { });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多