Channel synchronisation - fthoms/jiminy GitHub Wiki

Channel Synchronisation

We can use channels to synchronise excecution across tasks. The following code shows how we can use a channel to signal completion to another thread, which is then allowed to continue when the worker is done.

sealed class ChannelSynchronisation : IExample {
    public void Run() {
        var done = Channel.Make<bool>();
        Task.Run(() => Worker(done));
        done.Receive(); //wait for worker to complete
        Console.WriteLine("done");
    }

    void Worker(IChannel<bool> done) {
        Task.Delay(1000).Wait();
        done.Send(true); //signal completion
    }
}
⚠️ **GitHub.com Fallback** ⚠️