UniRx: Concat
Observable.Concat()
は複数の IObservable<T>
を順番に実行するオペレーターです。
using System; using UniRx; using UnityEngine; public class Main : MonoBehaviour { void Start() { // 1 秒ごとに通知 var a = Observable.Interval(TimeSpan.FromSeconds(1)).Take(3); // 5 秒ごとに通知 var b = Observable.Interval(TimeSpan.FromSeconds(5)).Take(2); var c = a.Concat(b); c.Subscribe(e => Debug.Log("e: " + e), () => Debug.Log("OnCompleted")); } }
実行結果です。
[21:00:05] e: 0 [21:00:06] e: 1 [21:00:07] e: 2 [21:00:12] e: 0 [21:00:17] e: 1 [21:00:17] OnCompleted
先頭の数値は、ログの出力時刻です。IObservable
の a
から 3 つ通知を受け取った後に b
の処理が開始されています。