public ValueTask FlushAsync()
        {
            lock (_contextLock)
            {
                if (_isInitialized)
                {
                    return(new ValueTask(Task.CompletedTask));
                }

                NativeMethods.HttpEnableWebsockets(_handler);

                var init = GetInitializeOperation();
                init.Initialize(_handler);

                var continuation = init.Invoke();

                if (continuation != null)
                {
                    _isInitialized = true;
                }
                else
                {
                    _initializationFlush = init;
                }

                return(new ValueTask(init, 0));
            }
        }
        public void NotifyCompletion(int hr, int bytes)
        {
            _isInitialized = true;

            var init = _initializationFlush;

            if (init == null)
            {
                throw new InvalidOperationException("Unexpected completion for WebSocket operation");
            }

            var continuation = init.Complete(hr, bytes);

            _initializationFlush = null;

            continuation.Invoke();
        }
 private void ReturnOperation(AsyncInitializeOperation operation) =>
 Volatile.Write(ref _cachedAsyncInitializeOperation, operation);