mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-03-31 11:39:19 +00:00
Updated solution
This commit is contained in:
parent
064f057b10
commit
87438d555f
@ -17,8 +17,14 @@ impl Queue {
|
|||||||
fn send_tx(q: Queue, tx: mpsc::Sender<u32>) {
|
fn send_tx(q: Queue, tx: mpsc::Sender<u32>) {
|
||||||
// Clone the sender `tx` first.
|
// Clone the sender `tx` first.
|
||||||
let tx_clone = tx.clone();
|
let tx_clone = tx.clone();
|
||||||
|
|
||||||
|
// Defining the data in new variables.
|
||||||
|
// `q` cannot be moved simultaneously into multiple places.
|
||||||
|
let first_half = q.first_half;
|
||||||
|
let second_half = q.second_half;
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
for val in q.first_half {
|
for val in first_half {
|
||||||
println!("Sending {val:?}");
|
println!("Sending {val:?}");
|
||||||
// Then use the clone in the first thread. This means that
|
// Then use the clone in the first thread. This means that
|
||||||
// `tx_clone` is moved to the first thread and `tx` to the second.
|
// `tx_clone` is moved to the first thread and `tx` to the second.
|
||||||
@ -28,7 +34,7 @@ fn send_tx(q: Queue, tx: mpsc::Sender<u32>) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
for val in q.second_half {
|
for val in second_half {
|
||||||
println!("Sending {val:?}");
|
println!("Sending {val:?}");
|
||||||
tx.send(val).unwrap();
|
tx.send(val).unwrap();
|
||||||
thread::sleep(Duration::from_millis(250));
|
thread::sleep(Duration::from_millis(250));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user