Skip to content

Dynamic Supervisor for gleam/erlang/otp

Notifications You must be signed in to change notification settings

kodumbeats/dinosoup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kodumbeats/dinosoup

Package Version Hex Docs

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.

Usage

Add the library to your Gleam project:

gleam add dinosoup

Then, in your code:

import dinosoup
import some.{message_handler}

pub fn main() {
  let assert Ok(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
  let assert Ok(Nil) = sup |> dinosoup.kill_child(pid)

  // and now only one remains
  let assert [_] = sup |> dinosoup.children()
}

Further documentation can be found at https://hexdocs.pm/dinosoup.

Development

gleam format # Format the code
gleam run   # Run the project
gleam test  # Run the tests
gleam shell # Run an Erlang shell

TODO

  • 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

About

Dynamic Supervisor for gleam/erlang/otp

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published