{"action":"opened","issue":{"url":"https://api.github.com/repos/Azure/amqpnetlite/issues/73","labels_url":"https://api.github.com/repos/Azure/amqpnetlite/issues/73/labels{/name}","comments_url":"https://api.github.com/repos/Azure/amqpnetlite/issues/73/comments","events_url":"https://api.github.com/repos/Azure/amqpnetlite/issues/73/events","html_url":"https://github.com/Azure/amqpnetlite/issues/73","id":123736206,"number":73,"title":"Cancelable SenderLink.Send method","user":{"login":"robreeves","id":5604993,"avatar_url":"https://avatars.githubusercontent.com/u/5604993?v=3","gravatar_id":"","url":"https://api.github.com/users/robreeves","html_url":"https://github.com/robreeves","followers_url":"https://api.github.com/users/robreeves/followers","following_url":"https://api.github.com/users/robreeves/following{/other_user}","gists_url":"https://api.github.com/users/robreeves/gists{/gist_id}","starred_url":"https://api.github.com/users/robreeves/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robreeves/subscriptions","organizations_url":"https://api.github.com/users/robreeves/orgs","repos_url":"https://api.github.com/users/robreeves/repos","events_url":"https://api.github.com/users/robreeves/events{/privacy}","received_events_url":"https://api.github.com/users/robreeves/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-23T23:26:12Z","updated_at":"2015-12-23T23:26:12Z","closed_at":null,"body":"I think the library could benefit from the SenderLink.Send methods to be cancelable. For example I may be in the middle of sending a large message and receive a stop request of some sorts (i.e. a Windows service stop). I think it would also be helpful for SenderLink.SendAsync to be cancelable. \r\n\r\nWhat do you think? Would you be open to a pull request that adds cancelable SenderLink.Send overloads or updates the existing methods?\r\n\r\nHere is a quick example of what I mean with some stolen code from the synchronous SenderLink.Send.\r\n\r\n    public static class SenderLinkExtensions\r\n    {\r\n        public static void Send(this SenderLink sender, Message message, CancellationTokenSource cancelToken)\r\n        {\r\n            using (var mres = new ManualResetEvent(false))\r\n            {\r\n                Outcome outcome = null;\r\n                OutcomeCallback callback = (m, o, s) =>\r\n                {\r\n                    outcome = o;\r\n                    mres.Set();\r\n                };\r\n\r\n                sender.Send(message, callback, null);\r\n\r\n                while (true)\r\n                {\r\n                    //Check if canceled\r\n                    cancelToken.Token.ThrowIfCancellationRequested();\r\n\r\n                    if (mres.WaitOne(100))\r\n                    {\r\n                        //Handle error outcomes\r\n                        if (outcome != null)\r\n                        {\r\n                            if (outcome.Descriptor.Code == 38)\r\n                            {\r\n                                Released released = (Released)outcome;\r\n                                throw new AmqpException(ErrorCode.MessageReleased, null);\r\n                            }\r\n                            else if (outcome.Descriptor.Code == 37)\r\n                            {\r\n                                Rejected rejected = (Rejected)outcome;\r\n                                throw new AmqpException(rejected.Error);\r\n                            }\r\n                        }\r\n\r\n                        return;\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }"}}