我需要从服务器检索无限量的数据。应该以以下方式进行:
如何使用可观察对象做到这一点?
就目前而言,我只能想到带有类似功能的递归可观察调用。
const send = execSend() {
this.send(message).subscribe(resp => {
if (resp === 'end') {
subscriber.next(byteArr.join(''));
console.log('finished');
subscriber.complete();
} else {
byteArr.push(resp);
execSend();
}
});
}();
答案 0 :(得分:1)
以下内容应复制您的想法:完成之前发出1个事件。
for i in color:
if i == " ":
color = color.split()
x = color[0]
y = color[1]
z = color[2]
else: # If HEX color
if color[0] == "#": # if it starts with "#"
color = color[1:]
decX = color[0:1]
decY = color[2:3]
decZ = color[4:5]
x = int(decX, 16)
y = int(decY, 16)
z = int(decZ, 16)
print(color, x, y, z)
else: # if it's without "#"
decX = color[0:1]
decY = color[2:3]
decZ = color[4:5]
x = int(decX, 16)
y = int(decY, 16)
z = int(decZ, 16)
print(color, x, y, z)
您可以看到它在this blitz
中工作答案 1 :(得分:0)
未经测试,但您可以尝试此模式
exec=()=>http.get(....)
exec().pipe(
expand((resp)=>exec()),
takeWhile(resp=>resp !== 'end'),
scan((acc,curr)=>acc.concat(curr),[])
).subscribe()
答案 2 :(得分:-1)
类似这样的东西:
let todo = true;
interval(100).pipe(
takeWhile(()=>todo),
concatMap(()=>getStuff())
).subscribe(data => {
todo = !isFinished(data);
});