Interval
间隔一定的时间单位持续给订阅者通知信息,图解
示例代码
public class No03_Interval : MonoBehaviour
{
void Start()
{
var intervalStream = Observable.Interval(TimeSpan.FromSeconds(3f), Scheduler.MainThread);
var disposable = intervalStream.Subscribe(Next, Error, Complete);
disposable.AddTo(this);
}
void Next(long times)
{
Debug.LogFormat("间隔3秒输出,第{0}次", times);
}
void Error(Exception ex)
{
Debug.LogException(ex);
}
void Complete()
{
Debug.LogFormat("Complete");
}
}
代码解析
Interval第一个参数是时间单位,Scheduler是调度器,表明这个Interval在哪个线程里面来执行
RX默认的调度器拥有的分支调度包括,4个
Scheduler.DefaultSchedulers