Cysharp / R3

The new future of dotnet/reactive and UniRx.
MIT License
1.71k stars 70 forks source link

Want to flow the elements of the array one frame at a time #222

Open kochounoyume opened 3 weeks ago

kochounoyume commented 3 weeks ago

As a goal, I want to do what the title says.

For example, the following source code does not work well in practice (because Complete is issued inside ToObservable()), but it may convey the image.

Any good ideas?


using Cysharp.Threading.Tasks;
using R3;
using UnityEngine;

public sealed class Test : MonoBehaviour
{
    void Start()
    {
        string[] array = { "a", "b", "c" };
        array
            .ToObservable()
            .SubscribeAwait(static async (element, token) =>
            {
                Debug.Log(element);
                await UniTask.Yield(token);
            }, AwaitOperation.Sequential);
    }
}