10000 GitHub - farhadi/singleton_supervisor: Singleton supervisor within an erlang cluster
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

farhadi/singleton_supervisor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SingletonSupervisor

Singleton supervisor within an erlang cluster

Installation

The package can be installed by adding singleton_supervisor to your list of dependencies in mix.exs:

def deps do
  [
    {:singleton_supervisor, "~> 0.2.1"}
  ]
end

Usage

SingletonSupervisor can be added as a child to a supervision tree but should not be used as the top level application supervisor:

defmodule MyApp.Application do
  use Application

  def start(_type, _args) do
    children = [
      {SingletonSupervisor,
       strategy: :one_for_one,
       name: {:global, MyApp.SingletonSupervisor},
       children: [
         # Children of SingletonSupervisor
       ]}
    ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

SingletonSupervisor by default uses {:global, SingletonSupervisor} as process name and if you want to use another name make sure you use a distributed registry that takes care of killing duplicate instances.

SingletonSupervisor can also be used as a module-based supervisor:

defmodule MyApp.SingletonSupervisor do
  use Supervisor

  def start_link(init_arg) do
    SingletonSupervisor.start_link(__MODULE__, init_arg, name: {:global, __MODULE__})
  end

  def init(_init_arg) do
    children = [
      # Children of SingletonSupervisor
    ]

    Supervisor.init(children, strategy: :one_for_one)
  end
end

About

Singleton supervisor within an erlang cluster

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0