Skip to content

Commit e06c7d1

Browse files
authored
Document how to use job send and job recv (#2006)
1 parent 80f9bab commit e06c7d1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

book/background_jobs.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,35 @@ job unfreeze 1
9696
# we're back in vim
9797
```
9898

99+
## Communicating between jobs
100+
101+
Data can be sent to a job using `job send <id>`, and the job can receive it using `job recv`:
102+
103+
```nu
104+
let jobId = job spawn {
105+
job recv | save sent.txt
106+
}
107+
108+
'hello from the main thread' | job send $jobId
109+
110+
sleep 1sec
111+
112+
open sent.txt
113+
# => hello from the main thread
114+
```
115+
116+
The main thread has a job ID of 0, so you can also send data in the other direction:
117+
118+
```nu
119+
job spawn {
120+
sleep 1sec
121+
'Hello from a background job' | job send 0
122+
}
123+
124+
job recv
125+
# => Hello from a background job
126+
```
127+
99128
## Exit Behavior
100129

101130
Unlike many other shells, Nushell jobs are **not** separate processes,

0 commit comments

Comments
 (0)