Example #1
0
        public int NonAsyncWithFixedBuffer()
        {
            TestReads tr       = new TestReads(this.NumBytes);
            bool      finished = false;
            int       final    = -1;

            while (!finished)
            {
                var(more, val) = tr.ReadNextWithFixedBuffer();
                finished       = !more;
                final          = val;
            }

            return(final);
        }
Example #2
0
        public int RawBytesAndSpan()
        {
            TestReads tr       = new TestReads(this.NumBytes);
            bool      finished = false;
            int       final    = -1;

            while (!finished)
            {
                var(more, val) = tr.ReadNextWithSpan(this.NumBytes);
                finished       = !more;
                final          = val;
            }

            return(final);
        }
Example #3
0
        public int Async()
        {
            CancellationTokenSource cts = new CancellationTokenSource();
            TestReads tr       = new TestReads(this.NumBytes);
            bool      finished = false;
            int       final    = -1;

            while (!finished)
            {
                var(more, val) = tr.ReadNextAsync(cts.Token).Result;
                finished       = !more;
                final          = val;
            }

            return(final);
        }
Example #4
0
        public int AsyncWithAwait()
        {
            int final = -1;

            return(DoItAsync().Result);

            async Task <int> DoItAsync()
            {
                CancellationTokenSource cts = new CancellationTokenSource();
                TestReads tr       = new TestReads(this.NumBytes);
                bool      finished = false;

                while (!finished)
                {
                    var(more, val) = await tr.ReadNextAsync(cts.Token);

                    finished = !more;
                    final    = val;
                }

                return(final);
            }
        }