I have some problem while working on Elixir.
This is my mix.exs
...
defmodule FlockTest.Mixfile do
use Mix.Project
def project do
[app: :flock_test,
version: "0.1.0",
elixir: "~> 1.4",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps()]
end
# Configuration for the OTP application
#
# Type "mix help compile.app" for more information
def application do
# Specify extra applications you'll use from Erlang/Elixir
[
extra_applications: [:logger],
mod: {FlockTest, []}
]
end
...
...
and this is code for FlockTest
.
defmodule FlockTest do
@moduledoc """
Documentation for FlockTest.
"""
def start(_type, _args) do
IO.puts "Start Flock"
end
end
I run this code with mix run --no-halt
but this caused error like this.
=INFO REPORT==== 12-Nov-2017::17:47:39 ===
application: logger
exited: stopped
type: temporary
** (Mix) Could not start application flock_test: FlockTest.start(:normal,
[]) returned a bad value: :ok
Am I doing something wrong?
Your application's start/2
function should start and return the top level process of the application, usually a supervisor instance. Right now you return the value returned by IO.puts
, which is :ok
on success. The valid return values are {:ok, pid} | {:ok, pid, state} | {:error, reason :: term}
as documented here. For an example of this, you can create a new application using mix new foo --sup
and check out lib/foo/application.ex
. Here's how its start/2
looks like:
def start(_type, _args) do
# List all child processes to be supervised
children = [
# Starts a worker by calling: A.Worker.start_link(arg)
# {A.Worker, arg},
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: A.Supervisor]
Supervisor.start_link(children, opts)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With