Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions book/background_jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,35 @@ job unfreeze 1
# we're back in vim
```

## Communicating between jobs

Data can be sent to a job using `job send <id>`, and the job can receive it using `job recv`:

```nu
let jobId = job spawn {
job recv | save sent.txt
}

'hello from the main thread' | job send $jobId

sleep 1sec

open sent.txt
# => hello from the main thread
```

The main thread has a job ID of 0, so you can also send data in the other direction:

```nu
job spawn {
sleep 1sec
'Hello from a background job' | job send 0
}

job recv
# => Hello from a background job
```

## Exit Behavior

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