mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:16:30 +00:00
c1b5b5fee2
make inference in batches, fix c# handling, add overlap handling
28 lines
929 B
C#
28 lines
929 B
C#
using MessagePack;
|
|
using NetMQ;
|
|
using NetMQ.Sockets;
|
|
|
|
namespace Azaion.CommonSecurity;
|
|
|
|
public static class ZeroMqExtensions
|
|
{
|
|
public static T? Get<T>(this DealerSocket dealer, Func<byte[], bool>? shouldInterceptFn = null, int retries = 24, int tryTimeoutSeconds = 5, CancellationToken ct = default) where T : class
|
|
{
|
|
var tryNum = 0;
|
|
while (!ct.IsCancellationRequested && tryNum++ < retries)
|
|
{
|
|
if (!dealer.TryReceiveFrameBytes(TimeSpan.FromSeconds(tryTimeoutSeconds), out var bytes))
|
|
continue;
|
|
|
|
if (shouldInterceptFn != null && shouldInterceptFn(bytes))
|
|
return null;
|
|
|
|
return MessagePackSerializer.Deserialize<T>(bytes);
|
|
}
|
|
|
|
if (!ct.IsCancellationRequested)
|
|
throw new Exception($"Unable to get {typeof(T).Name} after {tryNum} retries, {tryTimeoutSeconds} seconds each");
|
|
|
|
return null;
|
|
}
|
|
} |