Azure / amqpnetlite

AMQP 1.0 .NET Library
Apache License 2.0
396 stars 141 forks source link

SendAsync SenderLink with OutcomeCallback callback #586

Closed Gsantomaggio closed 1 week ago

Gsantomaggio commented 1 week ago

Hi, Sorry if I opened an issue, but there is no discussion section.

I am looking for a way to use the OutcomeCallback with the AsyncSend, like:

Can the following pattern be implemented with the AsyncSend()?

       _senderLink.Send(message, (sender, message1, outcome, state) =>
            {
                Console.WriteLine($"Message sent {state}  {outcome} ");
                message1.Dispose();
            }, this);
xinchen10 commented 1 week ago

Yes, you can. Just make sure you do not make a blocking call in the callback. For example, calling _senderLink.Close() in the callback will cause a deadlock.

Gsantomaggio commented 1 week ago

Thank you @xinchen10 , Maybe I am missing something but there is no the API:

 _senderLink.SendAsync(message, (sender, message1, outcome, state) =>
            {
                Console.WriteLine($"Message sent {state}  {outcome} ");
                message1.Dispose();
            }, this);
xinchen10 commented 1 week ago

It is the Send(Message message, OutcomeCallback callback, object state) method. The [Operation]Async naming convention is only for methods with Task return type. https://github.com/Azure/amqpnetlite/blob/1dcc457828a8b368ffa2a9ebfa4c5468db2004f8/src/SenderLink.cs#L140C20-L140C82

Gsantomaggio commented 1 week ago

Thank you