Add examples for receiving data from a job (#16372)

# Description

The existing examples cover how to send data to a job, but I think it
will be much more common to want to receive data from a job.

# User-Facing Changes

Just documentation, though it may be worth highlighting anyway. I really
thought for a while that this was not possible yet. See also my book PR
https://github.com/nushell/nushell.github.io/pull/2006 (`job send` and
`job recv` were not documented in the book at all).
This commit is contained in:
Harper Andrews
2025-08-08 18:39:44 -05:00
committed by GitHub
parent 3dead9a001
commit e8579a9268
2 changed files with 19 additions and 7 deletions

View File

@ -116,6 +116,11 @@ in no particular order, regardless of the specified timeout parameter.
description: "Get a message or fail if no message is available immediately",
result: None,
},
Example {
example: "job spawn { sleep 1sec; 'hi' | job send 0 }; job recv",
description: "Receive a message from a newly-spawned job",
result: None,
},
]
}
}

View File

@ -101,10 +101,17 @@ This command never blocks.
}
fn examples(&self) -> Vec<Example> {
vec![Example {
vec![
Example {
example: "let id = job spawn { job recv | save sent.txt }; 'hi' | job send $id",
description: "Send a message to a newly spawned job",
description: "Send a message from the main thread to a newly-spawned job",
result: None,
}]
},
Example {
example: "job spawn { sleep 1sec; 'hi' | job send 0 }; job recv",
description: "Send a message from a newly-spawned job to the main thread (which always has an ID of 0)",
result: None,
},
]
}
}