2 ms·
The Rust examples seemed a little bit oddly structured to me; the case of collecting a value from a single thread would be just as easily solved by returning fr
by Lorkki 8y ago
The Rust examples seemed a little bit oddly structured to me; the case of collecting a value from a single thread would be just as easily solved by returning from the closure and receiving it through join(): https://gist.github.com/lorkki/e7386df8fff186b3e473994e9d31bee0#file-thread-example-1-rs https://gist.github.com/lorkki/e7386df8fff186b3e473994e9d31b...
The power of channels could be illustrated better by adapting the next example to show how you can avoid shared state completely: https://gist.github.com/lorkki/e7386df8fff186b3e473994e9d31bee0#file-thread-example-2-rs https://gist.github.com/lorkki/e7386df8fff186b3e473994e9d31b...
It's also worth noting that a more versatile channel implementation than mpsc can be found in the crossbeam crate, in case you're thinking of using them for anything more serious.