angular - 可观察:在添加新项目后处理数组中的项目而不重新开始
问题描述
我有一系列搅拌,在一段时间后我对每个项目按顺序执行一些操作。我想要的是,每当我向数组添加(或删除)Item 时,元素必须自己“排队”并等待轮到它被处理。但是我现在得到的是,每当我向数组添加(或删除)Item 时,操作都会从数组的第一项开始。这是我的代码的存根:
private _items = new Subject<string[]>();
private items: string[]=[];
calledMethodOnAction(){
this._items.pipe(concatAll())
.pipe(
concatMap(r => of(this.processingItem(r))
.pipe(delay(5000)))
).subscribe();
}
processingItem(r){
//Process data
}
addItem(newItem:string){
const index = this.items.findIndex(f => f.item === newItem);
if (index <= -1) {items.push(newItem);}
this._items.next(Object.assign([],items))
}
removeProcessedItem(item){
const index = this.items.findIndex(f => f.item === item);
if (index > -1) {
this.items.splice(index, 1);
}
this._items.next(Object.assign([],items))
}
我是 RxJs 的新手。请让我知道我在这里做错了什么。
谢谢!
解决方案
推荐阅读
- c++ - 无法弄清楚 GCC 11.1 编译器错误是什么意思
- java - Vaadin 14 - 无法让 Details/AccordionPanel 使用窗口宽度
- python - 在海龟赛跑中,如何让海龟停在特定坐标?
- node.js - 如何在已创建的 nodejs 身份验证之上添加两个因素身份验证?
- java - 如何设置 JOGL?
- python - 如何在 Python 中导出 docplex 解决方案?
- unit-testing - 为单个接口编写测试并为多个实现运行它们
- python - 未找到 conda 的 R 包
- reactjs - Rescript-react:创建隐藏的画布元素
- java - 线程“主”org.openqa.selenium.WebDriverException 中的异常:返回值无法转换为 WebElement:{stacktrace=Backtrace: