|
| 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