-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95e2b59
commit b2395ec
Showing
4 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//// Todo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//// This module implements a shit actor that crashes every now and then. | ||
//// Having an actor that fails every now and then will help us test out our supervisors. | ||
//// It's also a nice refresher on actors. Read the code and make sure it makes sense. | ||
|
||
import gleam/otp/actor | ||
import gleam/erlang/process.{type Subject} | ||
import prng/random | ||
|
||
pub fn new() -> Result(Subject(Message), actor.StartError) { | ||
actor.start(Nil, handle_message) | ||
} | ||
|
||
pub fn shutdown(subject: Subject(Message)) { | ||
actor.send(subject, Shutdown) | ||
} | ||
|
||
pub fn play_game(subject: Subject(Message)) -> String { | ||
let msg_generator = random.weighted(#(0.9, Duck), [#(0.1, Goose)]) | ||
let msg = random.random_sample(msg_generator) | ||
actor.call(subject, msg, 1000) | ||
} | ||
|
||
pub type Message { | ||
Duck(client: Subject(String)) | ||
Goose(client: Subject(String)) | ||
Shutdown | ||
} | ||
|
||
fn handle_message(message: Message, _state: Nil) -> actor.Next(Message, Nil) { | ||
case message { | ||
Duck(client) -> { | ||
actor.send(client, "duck") | ||
actor.continue(Nil) | ||
} | ||
Goose(_) -> panic as "Oh shit it's a fucking goose!!!!" | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
Shutdown -> actor.Stop(process.Normal) | ||
} | ||
} |
amazing :)