switchMap can chain two HTTP requests together, creating one request based on the results of the first request.

But the result observable did not have the data of the first request, instead it only had access to the data of the second HTTP request.

If we would like to have both the data of the first HTTP request and deliver it together with the data of the second request, we could use a selector function (notice the second argument passed to switchMap):

sequentialRequests() {

const sequence$ = this.http.get<Course>(
'/courses/-KgVwEBq5wbFnjj7O8Fp.json')
.switchMap(course => {
course.description+= ' - TEST ';
return this.http.put('/courses/-KgVwEBq5wbFnjj7O8Fp.json', course)
},
(firstHTTPResult, secondHTTPResult) =>
[firstHTTPResult, secondHTTPResult]); sequence$.subscribe(
values => console.log("result observable ", values)
); }

Other example:

//emit immediately, then every 5s
const source = Rx.Observable.timer(, );
//switch to new inner observable when source emits, invoke project function and emit values
const example = source.switchMap(() => Rx.Observable.interval(), (outerValue, innerValue, outerIndex, innerIndex) => ({outerValue, innerValue, outerIndex, innerIndex}));
/*
Output:
{outerValue: 0, innerValue: 0, outerIndex: 0, innerIndex: 0}
{outerValue: 0, innerValue: 1, outerIndex: 0, innerIndex: 1}
{outerValue: 1, innerValue: 0, outerIndex: 1, innerIndex: 0}
{outerValue: 1, innerValue: 1, outerIndex: 1, innerIndex: 1}
*/
const subscribe = example.subscribe(val => console.log(val));

[RxJS] How To get the results of two HTTP requests made in sequence的更多相关文章

  1. Fedora 24中的日志管理

    Introduction Log files are files that contain messages about the system, including the kernel, servi ...

  2. Burp Suite使用详解一

    本文由阿德马翻译自国外网站,请尊重劳动成果,转载注明出处 Burp Suite是Web应用程序测试的最佳工具之一,其多种功能可以帮我们执行各种任务.请求的拦截和修改,扫描web应用程序漏洞,以暴力破解 ...

  3. Flooded!

    Flooded! Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5955   Accepted: 1800   Specia ...

  4. python——有一种线程池叫做自己写的线程池

    这周的作业是写一个线程池,python的线程一直被称为鸡肋,所以它也没有亲生的线程池,但是竟然被我发现了野生的线程池,简直不能更幸运~~~于是,我开始啃源码,实在是虐心,在啃源码的过程中,我简略的了解 ...

  5. Burp SuiteBurp Suite使用详解

    http://www.2cto.com/Article/201209/153312.html Burp Suite是Web应用程序测试的最佳工具之一,其多种功能可以帮我们执行各种任务.请求的拦截和修改 ...

  6. remove adapter

    Although adapter and other technical sequences can potentially occur in any location within reads, b ...

  7. burp suite 使用教程详解(外文翻译转)

    Burp Suite是Web应用程序测试的最佳工具之一,其多种功能可以帮我们执行各种任务.请求的拦截和修改,扫描web应用程序漏洞,以暴力破解登陆表单,执行会话令牌等多种的随机性检查.本文将做一个Bu ...

  8. python 大数据分析

    #coding:utf-8 ''' @author solq by 2016-01-06 main(目录,正则过滤文件名) 执行完最后打印结果 ''' import json import fnmat ...

  9. sphinx在c#.net平台下使用(一)

    Sphinx是由俄罗斯人Andrew Aksyonoff开发的一个可以结合MySQL,PostgreSQL全文检索引擎.意图为其他应用提供高速.低空间占用.高结果 相关度的全文搜索功能.是做站内全文搜 ...

随机推荐

  1. Vue_小练习

    <!DOCTYPE html> <html lang='en'> <head> <meta charset='UTF-8'> <meta name ...

  2. caioj 1063 动态规划入门(一维一边推1:美元和马克)

    这道题一开始我是这么想的 最后的答案肯定是某次的马克换回来的,但这个该怎么确定?? 实际上应该把范围缩小,只看最后一次和倒数第二次之间有什么联系. 可以发现,只有两种可能,最后一天换或者不换.换的话就 ...

  3. Java Web学习总结(21)——http协议响应状态码大全以及常用状态码

    http协议响应状态码大全以及常用状态码 当我们在浏览网页或是在查看服务器日志时,常会遇到3位数字的状态码,这3位数字是什么意思呢?其实,这3位数字是HTTP状态码,用来表示网页服务器HTTP响应状态 ...

  4. 新浪新闻按keyword抓取实例

    import urllib2 import requests #import MySQLdb import webbrowser import string import re from Beauti ...

  5. Java Security安全系列文档翻译笔记————KeyStore、密钥、证书、命令行实战

    发送方任务: 1.将文档.源代码打包到jar包(这样才干够签名) 2.在keystore中生成相应的Private key和Public key 3.用Private Key对jar包进行签名,这是j ...

  6. Erlang简单并行server

    Erlang简单并行服务器 (金庆的专栏) Erlang并行服务器为每一个Tcp连接创建相应的连接进程,处理client数据. 參考 Erlang程序设计(第2版)17.1.3 顺序和并行服务器 并行 ...

  7. ZOJ 1654 Place the Robots(放置机器人)------最大独立集

    Place the Robots http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1654 Time Limit: 5 Sec ...

  8. js---15深拷贝浅拷贝 原型链

    //&&得到的结果不是布尔类型,如果前面都是 true就执行最后一个,并返回最后一个表达式的值,前面有一个为false,后面不执行,返回前面表达式的值 var a = 3; var b ...

  9. Spark 1.6.1 源码分析

    由于gitbook网速不好,所以复制自https://zx150842.gitbooks.io/spark-1-6-1-source-code/content/,非原创,纯属搬运工,若作者要求,可删除 ...

  10. ble_app_hrs心率程序 nrf51822

    所用程序为: H:\keil\ARM\Device\Nordic\nrf51822\Board\pca10001\s110\ble_app_hrs 上面的路径是安装sdk之后生成在keil软件所在目录 ...