Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add run_once function for when polling is not needed #2

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.1.0 - 2024-10-25

- Add `run_once` function for when polling is not needed.

## v1.0.0 - 2024-10-21

- Initial release with `local_epmd`, `epmd` and `dns` strategies, as well as support
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,29 @@ pub fn main() {
}
```

### Run the refresh function once

If you don't need any sort of polling, or want to manage your the refresh lifecycle
yourself, you can call the `run_once` function to run the refresh function a single
time.

In this case, most of the configuration options will be ignored.

```gleam
import barnacle

pub fn main() {
// Configure your Barnacle
let barnacle =
barnacle.local_epmd()

// Run the refresh function once
barnacle.run_once(barnacle)

// Continue your program...
}
```

## Strategies

Barnacle ships with a few built-in strategies, but you can also supply your own by
Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "barnacle"
version = "1.0.0"
version = "1.1.0"

description = "Self-healing clusters for Gleam applications on the BEAM!"
licences = ["MIT"]
Expand Down
9 changes: 9 additions & 0 deletions src/barnacle.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@ pub fn child_spec(
})
}

/// Run the refresh function once only. This will not start the actor, and will
/// not do any polling.
///
/// In this case, most configuration options are irrelevant and will be ignored.
pub fn run_once(barnacle: Barnacle(error)) {
barnacle
|> refresh_nodes
}

/// Refresh a barnacle actor. This will attempt to connect to new nodes, and
/// disconnect from nodes that are no longer available.
///
Expand Down