using System.Globalization; using JunexisLang.Runtime; await using var channel = new Channel(capacity: 2); foreach (var temperature in new[] { 21.0, 24.0 }) { var sent = await channel.SendAsync(new Measurement("room-1", temperature)); if (sent != SendResult.Ok) throw new InvalidOperationException("Wyslanie nie zakonczylo sie sukcesem."); var received = await channel.RecvAsync(); if (!received.IsOk) throw new InvalidOperationException("Odbior nie zwrocil wartosci."); var measurement = received.Ok!.Value.Value; if (measurement.DeviceId != "room-1" || measurement.Celsius != temperature) throw new InvalidOperationException("Odebrana wiadomosc nie odpowiada wyslanej."); Console.WriteLine($"Odebrano {measurement.DeviceId}: {measurement.Celsius.ToString("0.0", CultureInfo.InvariantCulture)}"); } Console.WriteLine($"Liczniki: wyslano={channel.Metrics.Sent}, odebrano={channel.Metrics.Received}"); if (channel.Metrics.Sent != 2 || channel.Metrics.Received != 2) throw new InvalidOperationException("Niepoprawne liczniki."); internal sealed record Measurement(string DeviceId, double Celsius);