private async ValueTask OpenSocket(CancellationToken cancellationToken = default) { if (socket is object) { return; } using var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); await socketSemaphore.WaitAsync(-1, cts.Token); try { while (socket is null && !cts.Token.IsCancellationRequested) { try { socket = factory.RequesterOpen().ThenDial(uri).Unwrap(); socketConfigurator?.Invoke(socket); }catch (NngException exception) { if (exception.ErrorCode == nng.Native.Defines.NNG_ECONNREFUSED) { await Task.Delay(100, cts.Token); } else { throw; } } } } finally { socketSemaphore.Release(); } }
/// <summary> /// Create request node for request/reply protocol /// </summary> /// <returns>The create.</returns> /// <param name="factory">Factory.</param> /// <param name="url">URL.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public static NngResult <IReqSocket> RequesterCreate <T>(this IAPIFactory <T> factory, string url) => factory.Dial(factory.RequesterOpen(), url);