Skip to content

Commit

Permalink
Remove a bunch of unnecessary Arcs
Browse files Browse the repository at this point in the history
  • Loading branch information
ihaveint committed Sep 21, 2023
1 parent 62f4a59 commit 726e5d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions chorus_book/src/guide-projector.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ To create a `Projector`, you need to provide the target location and the transpo
# use chorus_lib::transport::local::{LocalTransport, LocalTransportChannel};
# use chorus_lib::core::{ChoreographyLocation, Projector};
# use chorus_lib::{LocationSet};
# let transport_channel = Arc::new(LocalTransportChannel::<LocationSet!(Alice, Bob)>::new());
# let alice_transport = LocalTransport::new(Alice, Arc::clone(&transport_channel));
# let transport_channel = LocalTransportChannel::<LocationSet!(Alice, Bob)>::new();
# let alice_transport = LocalTransport::new(Alice, transport_channel.clone());
# #[derive(ChoreographyLocation)]
# struct Alice;
# #[derive(ChoreographyLocation)]
Expand All @@ -35,8 +35,8 @@ To execute a choreography, you need to call the `epp_and_run` method on the `Pro
# use chorus_lib::transport::local::{LocalTransport, LocalTransportChannel};
# use chorus_lib::core::{ChoreographyLocation, Projector, Choreography, ChoreoOp};
# use chorus_lib::{LocationSet};
# let transport_channel = Arc::new(LocalTransportChannel::<LocationSet!(Alice, Bob)>::new());
# let alice_transport = LocalTransport::new(Alice, Arc::clone(&transport_channel));
# let transport_channel = LocalTransportChannel::<LocationSet!(Alice, Bob)>::new();
# let alice_transport = LocalTransport::new(Alice, transport_channel.clone());
# #[derive(ChoreographyLocation)]
# struct Alice;
# #[derive(ChoreographyLocation)]
Expand Down
18 changes: 9 additions & 9 deletions chorus_book/src/guide-transport.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The `local` transport is used to execute choreographies on the same machine on d
# struct Bob;
use chorus_lib::transport::local::LocalTransportChannel;

let transport_channel = Arc::new(LocalTransportChannel::<LocationSet!(Alice, Bob)>::new());
let transport_channel = LocalTransportChannel::<LocationSet!(Alice, Bob)>::new();
```

To use the `local` transport, first import the `LocalTransport` struct from the `chorus_lib` crate.
Expand All @@ -34,17 +34,17 @@ To use the `local` transport, first import the `LocalTransport` struct from the
# #[derive(ChoreographyLocation)]
# struct Alice;
# use chorus_lib::transport::local::LocalTransportChannel;
# let transport_channel = Arc::new(LocalTransportChannel::<LocationSet!(Alice)>::new());
# let transport_channel = LocalTransportChannel::<LocationSet!(Alice)>::new();
use chorus_lib::transport::local::{LocalTransport};

let alice_transport = LocalTransport::new(Alice, Arc::clone(&transport_channel));
let alice_transport = LocalTransport::new(Alice, transport_channel.clone());
```

Then build the transport by using the `LocalTransport::new` associated function, which takes a target location (explained in the [Projector section](./guide-projector.md)) and the `LocalTransportChannel`.

You can construct a `LocalTransport` instance by passing a target location(lained in the [Projector section](./guide-projector.md)) and a `std::sync::Arc` of `LocalTransportChannel` to the `new` method.

Because of the nature of the `Local` transport, you must make a `std::sync::Arc` from the `LocalTransportChannel`, by using the `std::sync::Arc::clone(&local_transport)`.
Because of the nature of the `Local` transport, you must use the same `LocalTransportChannel` instance for all locations. You can `clone` the `LocalTransprotChannel` instance and pass it to each `Projector::new` constructor.

```rust
# extern crate chorus_lib;
Expand All @@ -63,19 +63,19 @@ Because of the nature of the `Local` transport, you must make a `std::sync::Arc`
# fn run(self, op: &impl ChoreoOp<Self::L>) {
# }
# }
let transport_channel = Arc::new(LocalTransportChannel::<LocationSet!(Alice, Bob)>::new());
let transport_channel = LocalTransportChannel::<LocationSet!(Alice, Bob)>::new();
let mut handles: Vec<thread::JoinHandle<()>> = Vec::new();
{
// create a transport for Alice
let transport = LocalTransport::new(Alice, Arc::clone(&transport_channel));
let transport = LocalTransport::new(Alice, transport_channel.clone());
handles.push(thread::spawn(move || {
let p = Projector::new(Alice, transport);
p.epp_and_run(HelloWorldChoreography);
}));
}
{
// create another for Bob
let transport = LocalTransport::new(Bob, Arc::clone(&transport_channel));
let transport = LocalTransport::new(Bob, transport_channel.clone());
handles.push(thread::spawn(move || {
let p = Projector::new(Bob, transport);
p.epp_and_run(HelloWorldChoreography);
Expand Down Expand Up @@ -135,8 +135,8 @@ impl Choreography for HelloWorldChoreography {
}
}
let transport_channel = Arc::new(LocalTransportChannel::<LocationSet!(Alice)>::new());
let transport = LocalTransport::new(Alice, Arc::clone(&transport_channel));
let transport_channel = LocalTransportChannel::<LocationSet!(Alice)>::new();
let transport = LocalTransport::new(Alice, transport_channel.clone());
let projector = Projector::new(Alice, transport);
projector.epp_and_run(HelloWorldChoreography);
```

0 comments on commit 726e5d0

Please sign in to comment.