相关疑难解决方法(0)

使用RxJS进行批处理?

我猜这应该有点容易实现,但我遇到了麻烦(从概念上讲,我猜)找出如何解决它.

我所拥有的是一个返回JSON对象数组的API.我需要逐步浏览这些对象,并为每个对象进行另一个AJAX调用.问题是处理每个AJAX调用的系统一次只能处理两个活动调用(因为它是一个CPU密集型任务,可以挂钩到桌面应用程序中).

我想知道如何使用RxJS(使用版本5或4)来实现这一目标?

编辑:此外,是否可以同时运行一系列步骤.即

Downloading File: 1 Processing File: 1 Converting File: 1 Uploading File: 1 Downloading File: 2 Processing File: 2 Converting File: 2 Uploading File: 2 Downloading File: 3 Processing File: 3 Converting File: 3 Uploading File: 3

我尝试过这样的事情:

Rx.Observable.fromPromise(start())
    .concatMap(arr => Rx.Observable.from(arr))
    .concatMap(x => downloadFile(x))
    .concatMap((entry) => processFile(entry))
    .concatMap((entry) => convertFile(entry))
    .concatMap((entry) => UploadFile(entry))
    .subscribe(
        data => console.log('data', new Date().getTime(), data),
        error => logger.warn('err', error),
        complete => logger.info('complete')
    );
Run Code Online (Sandbox Code Playgroud)

然而,这似乎不起作用.例如,downloadFile不等待processFile,convertFile和uploadFile全部完成,而是下一个将在前一个完成后再次运行.

javascript rxjs rxjs5

5
推荐指数
1
解决办法
1733
查看次数

标签 统计

javascript ×1

rxjs ×1

rxjs5 ×1