三国卡牌客户端基础资源仓库
hch
4 天以前 cdac25a8e4f91a4663bf5f80994538dd263b757c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using Cysharp.Threading.Tasks.Internal;
using System.Threading;
 
namespace Cysharp.Threading.Tasks.Linq
{
    public static partial class UniTaskAsyncEnumerable
    {
        public static IUniTaskAsyncEnumerable<TElement> Repeat<TElement>(TElement element, int count)
        {
            if (count < 0) throw Error.ArgumentOutOfRange(nameof(count));
 
            return new Repeat<TElement>(element, count);
        }
    }
 
    internal class Repeat<TElement> : IUniTaskAsyncEnumerable<TElement>
    {
        readonly TElement element;
        readonly int count;
 
        public Repeat(TElement element, int count)
        {
            this.element = element;
            this.count = count;
        }
 
        public IUniTaskAsyncEnumerator<TElement> GetAsyncEnumerator(CancellationToken cancellationToken = default)
        {
            return new _Repeat(element, count, cancellationToken);
        }
 
        class _Repeat : IUniTaskAsyncEnumerator<TElement>
        {
            readonly TElement element;
            readonly int count;
            int remaining;
            CancellationToken cancellationToken;
 
            public _Repeat(TElement element, int count, CancellationToken cancellationToken)
            {
                this.element = element;
                this.count = count;
                this.cancellationToken = cancellationToken;
 
                this.remaining = count;
            }
 
            public TElement Current => element;
 
            public UniTask<bool> MoveNextAsync()
            {
                cancellationToken.ThrowIfCancellationRequested();
 
                if (remaining-- != 0)
                {
                    return CompletedTasks.True;
                }
 
                return CompletedTasks.False;
            }
 
            public UniTask DisposeAsync()
            {
                return default;
            }
        }
    }
}