Beispiel #1
0
        public AwaitableWrapper <Msg> RecvMsgR(BytesView buf)
        {
            if (_RecvMsgR_ra == null)
            {
                _RecvMsgR_ra   = new ReusableAwaiter <Msg>();
                _RecvMsgR_cont = () => {
                    if (!_RecvMsgR_awaiter.TryGetResult(out var r, out var ex))
                    {
                        _RecvMsgR_ra.SetException(ex);
                    }
                    else
                    {
                        _RecvMsgR_ra.SetResult(new Msg(r.bv));
                    }
                };
            }
            _RecvMsgR_ra.Reset();
            var awaiter = _RecvMsgR_awaiter = _readAsyncR(new BytesSegment(buf?.bytes, buf?.offset ?? 0, buf?.len ?? 0));

            if (awaiter.IsCompleted)
            {
                _RecvMsgR_cont();
            }
            else
            {
                awaiter.OnCompleted(_RecvMsgR_cont);
            }
            return(new AwaitableWrapper <Msg>(_RecvMsgR_ra));
        }
Beispiel #2
0
 public AwaitableWrapper(ReusableAwaiter <T> ra)
 {
     awaitable = ra ?? throw new ArgumentNullException(nameof(ra));
     result    = default(T);
 }