Channel directions - fthoms/jiminy GitHub Wiki

Channel Directions

Channel directions is a way to prevent tasks from

  • sending on a channel they should be reading from, or
  • receiving on a channel they should be sending on
sealed class ChannelDirections : IExample {
    public void Run() {
        var pings = Channel.Make<string>(1);
        var pongs = Channel.Make<string>(1);
        Ping(pings, "passed message");
        Pong(pings, pongs);
        Console.WriteLine(pongs.Receive().Message);
    }

    void Ping(ISend<string> pings, string msg) {
        pings.Send(msg);
    }

    void Pong(IReceive<string> pings, ISend<string> pongs) {
        var (msg,_) = pings.Receive();
        pongs.Send(msg);
    }
}

At the same time this improves readability of the code since it is clear that the Ping method should only send messages on the pings channel, and the Pong method should only receive messages from it.

⚠️ **GitHub.com Fallback** ⚠️