zeromq / netmq

A 100% native C# implementation of ZeroMQ for .NET
Other
2.97k stars 745 forks source link

Feature. NetMQSocket TryReceive with CancellationToken #1078

Open IliaPodolko opened 1 year ago

IliaPodolko commented 1 year ago

Hi, I have a DealerSocket (it is a child of NetMQSocket). And I want to use TryReceiveMultipartMessage method with cancellationToken. This extension method uses "TryReceive" method. if (!socket.TryReceive(ref msg, timeout))

TryReceive uses private field m_socketHandle to call "TryRecv" without cancellationToken. m_socketHandle.TryRecv(ref msg, timeout);

CancellationToken logic was implemented in https://github.com/zeromq/netmq/pull/876

So ideally we can just overload the NetMQSocket::TryReceive and pass cancellationToken. And create additional extension method TryReceiveMultipartMessage to use cancellationToken as well. Is it a bad idea or somebody knows another way how to terminate TryReceiveMultipartMessage? Because even if I dispose the socket - it does not interrupt the method immediately.