module main; import std.stdio, std.concurrency; void SendReceiveFunction() { bool cont = true; while (cont) { receive( // delegates are used to match the message type (int msgi) => writeln("Counting on you ... tee hee: ", msgi), (float msgf) => writeln("Thanks for the float ... you have won the prize for the best float: ", msgf), (string msgs) => writeln("Didn't want to string you along, but: ", msgs), (Tid sender) { cont = false; sender.send(-1); }, (Variant v) => writeln("Wow ... interesting data?") // Variant matches any type ); } } void main() { auto tid = spawn(&SendReceiveFunction); // spawn a new thread running SendReceiveFunction() foreach (i; 56 .. 87) tid.send(i); // send some integers tid.send(678.567f); // send a float tid.send("Hello from RJM Programming ... hope this sees you well."); // send a string tid.send(thisTid); // send a struct (Tid) receive((int x) => writeln("Main thread received message: ", x)); }