Skip to content

Commit

Permalink
docs(hydro_lang): add docs for processes
Browse files Browse the repository at this point in the history
  • Loading branch information
shadaj committed Jan 24, 2025
1 parent e43e785 commit daad9c3
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions docs/docs/hydro/locations/processes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,35 @@ sidebar_position: 0
---

# Processes
:::caution
The simplest type of location in Hydro is a process. A process represents a single machine running a piece of a Hydro program. When creating a process, you can pass in a type parameter that will be used as a marker to distinguish that process from others (and will also be used to mark logs originating at that process). For example, you can create a process with a marker of `Leader` to represent a leader in a distributed system:

The Hydro documentation is currently under active development! This page is a placeholder for future content.
```rust,no_run
# use hydro_lang::*;
struct Leader {}
:::
let flow = FlowBuilder::new();
let leader: Process<Leader> = flow.process::<Leader>();
```

Once we have a process, we can create live collections on that process (see [Live Collections](../live-collections/index.md) for more details). For example, we can create a stream of integers on the leader process:

```rust,no_run
# use hydro_lang::*;
# struct Leader {}
# let flow = FlowBuilder::new();
# let leader: Process<Leader> = flow.process::<Leader>();
let numbers = leader.source_iter(q!(vec![1, 2, 3, 4]));
```

## Networking
Because a process represents a single machine, it is straightforward to send data to and from a process. For example, we can send a stream of integers from the leader process to another process using the `send_bincode` method (which uses [bincode](https://docs.rs/bincode/latest/bincode/) as a serialization format). This automatically sets up network senders and receivers on the two processes.

```rust,no_run
# use hydro_lang::*;
# struct Leader {}
# let flow = FlowBuilder::new();
# let leader: Process<Leader> = flow.process::<Leader>();
let numbers = leader.source_iter(q!(vec![1, 2, 3, 4]));
let process2: Process<()> = flow.process::<()>();
let on_p2: Stream<_, Process<()>, _> = numbers.send_bincode(&process2);
```

0 comments on commit daad9c3

Please sign in to comment.