using InnovEnergy.Lib.Utils; namespace InnovEnergy.Lib.Channels.Framed; public class Channel : Connection { private readonly AsyncAction _Transmit; private readonly Async _Receive; public Channel(AsyncAction transmit, Async receive, AsyncAction? open = null, AsyncAction? close = null, CloseAfter closeAfter = CloseAfter.Error) : base(open, close, closeAfter) { _Transmit = transmit; _Receive = receive; } public async Task Transmit(Tx data) { try { await Open(); await _Transmit(data); await CloseAfterTransmit(); } catch { await CloseAfterError(); throw; } } public async Task Receive() { try { await Open(); var data = await _Receive(); await CloseAfterReceive(); return data; } catch { await CloseAfterError(); throw; } } } public class Channel : Channel { public Channel(AsyncAction transmit, Async receive, AsyncAction? open = null, AsyncAction? close = null, CloseAfter closeAfter = CloseAfter.Error) : base(transmit, receive, open, close, closeAfter) { } }