Hello, I have a 3 functions that load different table of my database. but pleas assume, I have these function.
defmodule WeddingCardWeb.AdminInvoicesController do
def fn1(invoice_id)
invoice_id + 1
end
def fn3(invoice_id)
invoice_id + 1
end
def fn3(invoice_id)
invoice_id + 1
end
end
now I want to load those functions in Task, I need to use Task.Supervisor, because it loads database.
now I edited my application file:
def start(_type, _args) do
# List all child processes to be supervised
children = [
WeddingCard.Repo,
WeddingCardWeb.Endpoint,
{Task.Supervisor, name: WeddingCardWeb.AdminInvoicesController}
]
opts = [strategy: :one_for_one, name: WeddingCard.Supervisor]
Supervisor.start_link(children, opts)
end
and for loading I use this:
def extera_finder(invoice_id) do
Task.Supervisor.async WeddingCardWeb.AdminInvoicesController, fn ->
:timer.sleep(10000)
IO.puts "by Shahryar tavakkoli #{invoice_id}"
end
end
but I don’t know how to create the code that loads my 3 functions, and put their result in a map instead of this code:
:timer.sleep(10000)
IO.puts "by Shahryar tavakkoli #{invoice_id}"
In the end I need like this: %{function1, function2, function3}
before I created a simple project with one function like this, but not 3 functions:
def extera_finder(invoice_id) do
Task.Supervisor.async WeddingCardWeb.AdminInvoicesController, fn ->
function_name(invoice_id)
end
end
def function_name(invoice_id) do
:timer.sleep(100)
invoice_id
|> Enum.map(fn inv -> "by Shahryar tavakkoli #{inv}" end)
|> IO.inspect
end
and I load it like this way:
cities = ["Singapore", "Monaco", "Vatican City", "Hong Kong", "Macaus", "Amol","Tehran","Esfahan","Zanjan"]
WeddingCardWeb.AdminInvoicesController.extera_finder cities
how can I do this with 3 functions?