Created
September 15, 2017 00:05
-
-
Save elcritch/dde692b0e367819ef3606a88c7621c0a to your computer and use it in GitHub Desktop.
Example task supervisor using a function handle in Elixir (nerves example)
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
require Logger | |
defmodule TestNpn.Application do | |
use Application | |
alias Nerves.Networking | |
@interface :eth0 | |
# See http://elixir-lang.org/docs/stable/elixir/Application.html | |
# for more information on OTP Applications | |
def start(_type, _args) do | |
import Supervisor.Spec, warn: false | |
# Define workers and child supervisors to be supervised | |
children = [ | |
worker(Task, [fn -> init_network() end], restart: :transient, id: TestNerves.Application.Network), | |
] | |
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html | |
# for other strategies and supported options | |
opts = [strategy: :one_for_one, name: TestNpn.Supervisor] | |
Supervisor.start_link(children, opts) | |
end | |
def init_network() do | |
Logger.info "Starting Networking:interface: #{inspect @interface} pid: #{inspect self()}" | |
{:ok, _} = Networking.setup @interface | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment