如何在TypeScript的ReactiveX / rxjs 5中使用exhaustMap

mar*_*tin 5 reactive-programming rxjs typescript angular

我想知道如何处理一个数组,其中每个值以指定的顺序返回Promise。例如,假设我要以此顺序调用多个Ajax调用:

var array = [
    'http://example.org',
    'http://otherexample.org',
    'http://anotherexample.org',
];
Run Code Online (Sandbox Code Playgroud)

基本上有一个相同的问题:在前一个问题解决之前,我如何使用RxJ推迟对AJAX调用的任何请求,建议使用flatMapFirst

由于我目前正在使用的beta-15TypeScript中使用Angular2(现在),因此rxjs@5.0.0-beta.2我发现它flatMapFirst已重命名为exhaustMap

但是该操作符未在Observable.ts中列出,因此我不能使用它。RxJS的捆绑版本https://code.angularjs.org/2.0.0-beta.15/Rx.js中甚至都不存在。

那么,我应该如何使用它呢?还是有其他方法可以满足我的需求?它的package.json列出了很多构建脚本,我是否应强制使用其中一个?

编辑:我应该提到我正在使用ReactiveX / rxjs库,而不是Reactive-Extensions / RxJS

mar*_*tin 5

接线员concatMap()做了这项工作:

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/concatMap';

var urls = [
  'https://httpbin.org/get?1',
  'https://httpbin.org/get?2',
  'https://httpbin.org/get?3',
  'https://httpbin.org/get?4',
  'https://httpbin.org/get?5',
];     

Observable.from(this.urls)
  .concatMap(url => http.get(url))
  .subscribe(response => console.log(response.url))
;
Run Code Online (Sandbox Code Playgroud)

打印到控制台:

https://httpbin.org/get?1
https://httpbin.org/get?2
https://httpbin.org/get?3
https://httpbin.org/get?4
https://httpbin.org/get?5
Run Code Online (Sandbox Code Playgroud)