private async UniTaskVoid WaitForAsync(
     IReadOnlyAsyncReactiveProperty <string> asyncReadOnlyReactiveProperty,
     CancellationToken token)
 {
     await asyncReadOnlyReactiveProperty
     .Queue()     // Queueを挟む
     .ForEachAwaitWithCancellationAsync(async(x, ct) =>
     {
         Debug.Log(x);
         await UniTask.Delay(1000, cancellationToken: ct);
     }, token);
 }
 private async UniTaskVoid WaitForAsync(
     IReadOnlyAsyncReactiveProperty <string> asyncReadOnlyReactiveProperty,
     CancellationToken token)
 {
     await asyncReadOnlyReactiveProperty
     // 1秒待ってから MoveNextAsync() を実行する
     .ForEachAwaitWithCancellationAsync(async (x, ct) =>
     {
         Debug.Log(x);
         await UniTask.Delay(1000, cancellationToken: ct);
     }, token);
 }
Exemplo n.º 3
0
        private async UniTaskVoid WaitForAsync(
            IReadOnlyAsyncReactiveProperty <int> asyncReadOnlyReactiveProperty,
            CancellationToken token)
        {
            // Valueプロパティで現在値を取得可能
            var current = asyncReadOnlyReactiveProperty.Value;

            Debug.Log($"Current:{current}");

            // 現在の値をスキップして、次の値に更新されるまで待つ
            var next = await asyncReadOnlyReactiveProperty.WaitAsync(token);

            Debug.Log($"Next:{next}");

            // IUniTaskAsyncEnumerable<T>として扱える
            // (LINQと組み合わせ可能)
            var result = await asyncReadOnlyReactiveProperty
                         // 負数になるまで待つ
                         .FirstOrDefaultAsync(x => x < 0, cancellationToken : token);

            Debug.Log($"LINQ:{result}");
        }