从数组创建无限可重复的 Observable [英] Create infinite repeatable Observable from array

查看:36
本文介绍了从数组创建无限可重复的 Observable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个数组 items

我知道我可以使用这个数组创建一个 observable

I know I can create an observable from this array using

Rx.Observable.fromArray(items)

我如何从这里创建一个惰性无限重复的可观察对象(即:只要有请求就重复这些项目)?

How do I create a lazily infinitely repeating observable from this (i.e.: repeating the items as long as they are being requested)?

尝试过

Rx.Observable.fromArray(items).repeat()

但这不会延迟执行,因此会锁定浏览器.

But this doesn't execute lazily and therefor locks up the browser.

推荐答案

你不能用 Observable 做到这一点.你想看看使用枚举.

You cannot do this with an Observable. You way want to look at using an Enumerable.

Reactive Extensions 的 Enumerable 风格被称为 Interective Extensions.

The Enumerable flavor of Reactive Extensions is known as Interective Extensions.

这篇关于从数组创建无限可重复的 Observable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆