A Elixir/DynamicSupervisor /:simple_one_for_one strategy for gleam/{erlang,otp}.
WORK IN PROGRESS - Use at your own risk pre v0.1.0 release on
hex
.
Add the library to your Gleam project:
gleam add dinosoup
Then, in your code:
importdinosoup
importsome.{message_handler}
pubfnmain(){
letassertOk(sup)=dinosoup.start()
// children must implement same behavior (e.g. use the same handler)
sup|>dinosoup.start_child(ChildSpec(["state"],message_handler))
sup|>dinosoup.start_child(ChildSpec(["different_state"],message_handler))
// to get at it later
let[#(pid,actor,spec),.._rest]=sup|>dinosoup.children()
// killed children stay dead, but Normal and Abnormal(reason)
// exits will be restarted
letassertOk(Nil)=sup|>dinosoup.kill_child(pid)
// and now only one remains
letassert[_]=sup|>dinosoup.children()
}
Further documentation can be found athttps://hexdocs.pm/dinosoup.
gleam format#Format the code
gleam run#Run the project
gleamtest#Run the tests
gleam shell#Run an Erlang shell
- Get
dinosoup.kill_child/2
working - Implement more sophisticated restart/timeout strategies
- Harmonize more closely with
gleam/otp/supervisor
behavior
made with <3 by kodumbeats