/// <summary>
/// Sends a message asynchronously.
/// </summary>
/// <param name="sender">The link.</param>
/// <param name="message">The message.</param>
/// <returns></returns>
public static async Task SendAsync(this SenderLink sender, Message message)
{
DeliveryState txnState = null;
#if NETFX || NETFX40
txnState = await TaskExtensions.GetTransactionalStateAsync(sender);
#endif
TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();
sender.Send(
message,
txnState,
(m, o, s) =>
{
var t = (TaskCompletionSource <object>)s;
if (o.Descriptor.Code == Codec.Accepted.Code)
{
t.SetResult(null);
}
else if (o.Descriptor.Code == Codec.Rejected.Code)
{
t.SetException(new AmqpException(((Rejected)o).Error));
}
else
{
t.SetException(new AmqpException(ErrorCode.InternalError, o.Descriptor.Name));
}
},
tcs);
await tcs.Task;
}