Skip to content

Commit

Permalink
type signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
bcpeinhardt committed Feb 29, 2024
1 parent 393bf53 commit af7f29f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 3 additions & 7 deletions src/supervisors.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,9 @@ pub fn main() {
// with which to intialize itself.
// There's a `supervisor.start_spec` function as well for tuning the
// restart frequency and the initial state to pass to children.
let children = fn(children) {
children
|> supervisor.add(game)
}

// We start the supervisor
let assert Ok(_supervisor_subject) = supervisor.start(children)
let assert Ok(_supervisor_subject) = supervisor.start(supervisor.add(_, game))

// The actor's init function sent us a subject for us to be able
// to send it messages
Expand All @@ -95,13 +91,13 @@ fn play_game(
parent_subject: Subject(Subject(duckduckgoose.Message)),
game_subject: Subject(duckduckgoose.Message),
times n: Int,
) {
) -> Nil {
case n {
// Base Case, recess is over
0 -> Nil
_ -> {
case duckduckgoose.play_game(game_subject) {
// We're just a noraml old duck, so we keep playing
// We're just a normal old duck, so we keep playing
Ok(msg) -> {
io.println(msg)
play_game(parent_subject, game_subject, n - 1)
Expand Down
6 changes: 4 additions & 2 deletions src/supervisors/a_shit_actor.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ pub fn start(

/// We provide this function in case we want to manually stop the actor,
/// but in reality the supervisor will handle that for us.
pub fn shutdown(subject: Subject(Message)) {
pub fn shutdown(subject: Subject(Message)) -> Nil {
actor.send(subject, Shutdown)
}

/// This is how we play the game.
/// We are at the whim of the child as to whether we are a
/// humble duck or the mighty goose.
pub fn play_game(subject: Subject(Message)) {
pub fn play_game(
subject: Subject(Message),
) -> Result(String, process.CallError(String)) {
let msg_generator = random.weighted(#(9.0, Duck), [#(1.0, Goose)])
let msg = random.random_sample(msg_generator)

Expand Down

0 comments on commit af7f29f

Please sign in to comment.