ReceiveInternal() приватный Метод

private ReceiveInternal ( MessageCallback callback, int timeout = 60000 ) : Amqp.Message
callback MessageCallback
timeout int
Результат Amqp.Message
Пример #1
0
        /// <summary>
        /// Receives a message asynchronously.
        /// </summary>
        /// <param name="receiver">The link.</param>
        /// <param name="timeout">The timeout in seconds.</param>
        /// <returns></returns>
        public static Task <Message> ReceiveAsync(this ReceiverLink receiver, int timeout = 60000)
        {
            TaskCompletionSource <Message> tcs = new TaskCompletionSource <Message>();

            try
            {
                var message = receiver.ReceiveInternal(
                    (l, m) => tcs.SetResult(m),
                    timeout);
                if (message != null)
                {
                    tcs.SetResult(message);
                }
            }
            catch (Exception exception)
            {
                tcs.SetException(exception);
            }

            return(tcs.Task);
        }
Пример #2
0
        /// <summary>
        /// Receives a message asynchronously.
        /// </summary>
        /// <param name="receiver">The receiver link.</param>
        /// <param name="timeout">The timeout in milliseconds to wait for a message.</param>
        /// <returns>A Task for the asynchronous receive operation. The result is a Message object
        /// if available; otherwise a null value.</returns>
        public static Task <Message> ReceiveAsync(this ReceiverLink receiver, int timeout = 60000)
        {
            TaskCompletionSource <Message> tcs = new TaskCompletionSource <Message>();
            var message = receiver.ReceiveInternal(
                (l, m) =>
            {
                if (l.Error != null)
                {
                    tcs.TrySetException(new AmqpException(l.Error));
                }
                else
                {
                    tcs.TrySetResult(m);
                }
            },
                timeout);

            if (message != null)
            {
                tcs.TrySetResult(message);
            }

            return(tcs.Task);
        }