Skip to content

Commit

Permalink
Change the book examples. The text itself still needs to be updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ihaveint committed Sep 18, 2023
1 parent 2bd32d5 commit a1ce6bb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions chorus_book/src/guide-input-and-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ let choreo = DemoChoreography {
input: "World".to_string(),
};

let projector = projector!(LocationSet!(Alice), Alice, transport);
let projector = Projector::new(Alice, transport);
projector.epp_and_run(choreo);
```

Expand Down Expand Up @@ -93,7 +93,7 @@ To run the sample choreography above at Alice, we use the `local` method to cons
# });
# }
# }
let projector_for_alice = projector!(LocationSet!(Alice), Alice, transport);
let projector_for_alice = Projector::new(Alice, transport);
// Because the target of the projector is Alice, the located value is available at Alice.
let string_at_alice: Located<String, Alice> = projector_for_alice.local("Hello, World!".to_string());
// Instantiate the choreography with the located value
Expand All @@ -120,7 +120,7 @@ For Bob, we use the `remote` method to construct the located value.
# });
# }
# }
let projector_for_bob = projector!(LocationSet!(Alice, Bob), Bob, transport);
let projector_for_bob = Projector::new(Bob, transport);
// Construct a remote located value at Alice. The actual value is not required.
let string_at_alice = projector_for_bob.remote(Alice);
// Instantiate the choreography with the located value
Expand Down Expand Up @@ -161,7 +161,7 @@ impl Choreography<String> for DemoChoreography {
# }
# }
let choreo = DemoChoreography;
let projector = projector!(LocationSet!(Alice), Alice, transport);
let projector = Projector::new(Alice, transport);
let output = projector.epp_and_run(choreo);
assert_eq!(output, "Hello, World!".to_string());
```
Expand All @@ -183,7 +183,7 @@ impl Choreography<Located<String, Alice>> for DemoChoreography {
}
}

let projector = projector!(LocationSet!(Alice), Alice, transport);
let projector = Projector::new(Alice, transport);
let output = projector.epp_and_run(DemoChoreography);
let string_at_alice = projector.unwrap(output);
assert_eq!(string_at_alice, "Hello, World!".to_string());
Expand Down
12 changes: 6 additions & 6 deletions chorus_book/src/guide-projector.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ To create a `Projector`, you need to provide the set of locations it can work wi
# extern crate chorus_lib;
# use chorus_lib::transport::local::LocalTransport;
# use chorus_lib::core::{ChoreographyLocation, Projector};
# use chorus_lib::{LocationSet, projector};
# let transport = LocalTransport::from(&[Alice::name(), Bob::name()]);
# use chorus_lib::{LocationSet};
# let transport = LocalTransport::<LocationSet!(Alice, Bob)>::new();
# #[derive(ChoreographyLocation)]
# struct Alice;
# #[derive(ChoreographyLocation)]
# struct Bob;
#

let projector = projector!(LocationSet!(Alice, Bob), Alice, transport);
let projector = Projector::new(Alice, transport);
```

Notice that the `Projector` is parameterized by its target location type. You will need one projector for each location to execute choreography.
Expand All @@ -31,8 +31,8 @@ To execute a choreography, you need to call the `epp_and_run` method on the `Pro
# extern crate chorus_lib;
# use chorus_lib::transport::local::LocalTransport;
# use chorus_lib::core::{ChoreographyLocation, Projector, Choreography, ChoreoOp};
# use chorus_lib::{LocationSet, projector};
# let transport = LocalTransport::from(&[Alice::name(), Bob::name()]);
# use chorus_lib::{LocationSet};
# let transport = LocalTransport::<LocationSet!(Alice, Bob)>::new();
# #[derive(ChoreographyLocation)]
# struct Alice;
# #[derive(ChoreographyLocation)]
Expand All @@ -45,7 +45,7 @@ To execute a choreography, you need to call the `epp_and_run` method on the `Pro
# }
#

# let projector = projector!(LocationSet!(Alice), Alice, transport);
# let projector = Projector::new(Alice, transport);
projector.epp_and_run(HelloWorldChoreography);
```

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 @@ -26,7 +26,7 @@ Because of the nature of the `Local` transport, you must use the same `LocalTran
# use chorus_lib::transport::local::LocalTransport;
# use std::thread;
# use chorus_lib::core::{ChoreographyLocation, ChoreoOp, Choreography, Projector};
# use chorus_lib::{LocationSet, projector};
# use chorus_lib::{LocationSet};
# #[derive(ChoreographyLocation)]
# struct Alice;
# #[derive(ChoreographyLocation)]
Expand All @@ -40,20 +40,20 @@ Because of the nature of the `Local` transport, you must use the same `LocalTran


let mut handles: Vec<thread::JoinHandle<()>> = Vec::new();
let transport = LocalTransport::from(&[Alice::name(), Bob::name()]);
let transport = LocalTransport::<LocationSet!(Alice, Bob)>::new();
{
// create a clone for Alice
let transport = transport.clone();
handles.push(thread::spawn(move || {
let p = projector!(LocationSet!(Alice, Bob), Alice, transport);
let p = Projector::new(Alice, transport);
p.epp_and_run(HelloWorldChoreography);
}));
}
{
// create another for Bob
let transport = transport.clone();
handles.push(thread::spawn(move || {
let p = projector!(LocationSet!(Alice, Bob), Bob, transport);
let p = Projector::new(Bob, transport);
p.epp_and_run(HelloWorldChoreography);
}));
}
Expand All @@ -74,12 +74,12 @@ The `new` constructor takes the name of the projection target and "configuration

```rust
{{#include ./header.txt}}
# use chorus_lib::transport::http::HttpTransport;
# use chorus_lib::transport::http::{HttpTransport};
# use chorus_lib::http_config;
# use std::collections::HashMap;
let mut config = HashMap::new();
config.insert(Alice::name(), ("localhost", 8080));
config.insert(Bob::name(), ("localhost", 8081));
let transport = HttpTransport::new(Alice::name(), &config);

let config = http_config!(Alice: ("localhost", 8080), Bob: ("localhost", 8081));
let transport = HttpTransport::new(Alice, &config);
```

In the above example, the transport will start the HTTP server on port 8080 on localhost. If Alice needs to send a message to Bob, it will use `http://localhost:8081` as the destination.
Expand Down
4 changes: 2 additions & 2 deletions chorus_book/src/header.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# extern crate chorus_lib;
# use chorus_lib::core::{ChoreoOp, Choreography, ChoreographyLocation, Projector, Located, Superposition, Runner};
# use chorus_lib::transport::local::LocalTransport;
# use chorus_lib::{LocationSet, projector};
# use chorus_lib::{LocationSet};
# #[derive(ChoreographyLocation)]
# struct Alice;
# #[derive(ChoreographyLocation)]
# struct Bob;
# #[derive(ChoreographyLocation)]
# struct Carol;
# let transport = LocalTransport::from(&[Alice::name(), Bob::name(), Carol::name()]);
# let transport = LocalTransport::<LocationSet!(Alice, Bob, Carol)>::new();

0 comments on commit a1ce6bb

Please sign in to comment.