Skip to content

Commit 1c1e366

Browse files
committed
Document how to support different distributed worker backends
1 parent 13ce55b commit 1c1e366

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ makedocs(;
3434
sitename = "DistributedNext",
3535
pages = [
3636
"DistributedNext" => "index.md",
37+
"support-preferences.md",
3738
"changelog.md"
3839
],
3940
warnonly = [:missing_docs, :cross_references],

docs/src/support-preferences.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Supporting both Distributed and DistributedNext
2+
3+
The [Distributed.jl](https://docs.julialang.org/en/v1/stdlib/Distributed/)
4+
standard library and DistributedNext are independent Julia modules, which means
5+
that they are not compatible at all. E.g. you cannot
6+
`DistributedNext.remotecall()` a worker added with `Distributed.addprocs()`. If
7+
you as a package developer want to make your package support both Distributed
8+
and DistributedNext, we suggest using
9+
[Preferences.jl](https://juliapackaging.github.io/Preferences.jl/stable/) to
10+
choose which library to load:
11+
```julia
12+
import Preferences: load_preference
13+
14+
const distributed_library_name = load_preference("distributed-library", "name")
15+
if distributed_library_name == "DistributedNext"
16+
using DistributedNext
17+
elseif distributed_library_name == "Distributed"
18+
using Distributed
19+
else
20+
error("Unsupported `distributed-library`: '$(distributed_library_name)'")
21+
end
22+
```
23+
24+
`distributed-library` is a top-level name that we recommend all packages who
25+
want to support switching backends use. The advantage of using a global
26+
preference instead of a per-package preference is that you can set it once:
27+
```julia
28+
import Preferences: set_preferences!
29+
30+
set_preferences!("distributed-library", "name" => "DistributedNext")
31+
```
32+
33+
And all packages that support the `distributed-library` preference will pick
34+
that up automatically so an end-user doesn't need to worry about setting
35+
preferences for all of the dependencies of the package that they want to use.

0 commit comments

Comments
 (0)