Amqp.TaskExtensions.ReceiveAsync C# (CSharp) Method

ReceiveAsync() public static method

Receives a message asynchronously.
public static ReceiveAsync ( this receiver, int timeout = 60000 ) : Task
receiver this The link.
timeout int The timeout in seconds.
return Task
        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;
        }