hernancuy
Hello everybody, I’m creating an app service aggregator, I created some modules, my idea it’s one module create tasks and inside other module create the await and select only one task, after you select one task you will be get a mutex, but this is another history. So I’m using this modules, one is “App” and another is “Driver”, when you add the name of app, It goes to create some Task async, the names that I’m gonna use, are created by a random name creation line. Until now it’s working well, the issue comes, when I try to execute the async from another module, says that I’m sending two arguments, I modified the function to get two params but not works, how can I get this async from other modules ? =D thanks my friends
defmodule Tarea2 do
defmodule App do
@app Apps
#### Start agent
def start do
Agent.start_link(fn -> %{} end, name: @app)
end
#### Start tasks from app
def task(app) do
for x <- 0..4 do
name = Enum.take_random(alphabet = Enum.to_list(?a..?e), 5)
:timer.sleep(1000)
name = Task.async(fn ->
pid = self()
ms = Enum.random(1..1000)
info = "Codigo #{name} : Hernan Cuy, lugar x lugar y, 20000"
Agent.update(@app, fn state -> Map.put(state, x, info) end)
:timer.sleep(120000)
IO.puts "#{inspect(pid)} finished in #{ms}ms"
Agent.update(@app, fn state -> Map.delete(state, x) end)
end)
end
end
#### getNotifications
def getNotifications do
Agent.get(@app, fn state -> Map.values(state) end)
end
def taskReceiver(name) do
Task.await(name)
end
end
defmodule Central do
@name __MODULE__
#### Start the principal agent
def start do
Agent.start_link(fn -> {} end, name: @name)
end
#### Add apps and start tasks
def aggregator(app) do
Agent.update(@name, fn state ->
Tuple.append(state, app)
end)
Tarea2.App.task(app)
end
#### Get all apps
def getApps do
Agent.get(@name, fn state -> state end )
end
end
defmodule Driver do
@mut MutexRegion
defstruct [name: "John", matricula: 28]
def aggregator(app) do
Tarea2.Central.start
Tarea2.App.start
Tarea2.Central.aggregator(app)
end
def taskReceiver do
msg = Tarea2.App.getNotifications
end
def selectTask do
taskSelected = String.trim(IO.gets("Ingrese codigo de solicitud a atender: "))
Tarea2.App.taskReceiver(taskSelected)
#Mutex.await(@defstruct, mutex2_id)
#Process.sleep(1000)
#Mutex.release(@defstruct, mutex1_id)
end
end
end
Here the error
iex(4)> Tarea2.Dirver.selectTask
Ingrese codigo de solicitud a atender: bcdae
** (FunctionClauseError) no function clause matching in Task.await/2
The following arguments were given to Task.await/2:
# 1
"bcdae"
# 2
5000
Attempted function clauses (showing 1 out of 1):
def await(-%Task{ref: ref, owner: owner} = task-, timeout) when -timeout == :infinity- or is_integer(timeout) and timeout >= 0
(elixir 1.13.2) lib/task.ex:794: Task.await/2
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
I’ve followed the Phoenix LiveView file upload code here Uploads — Phoenix LiveView v1.0.0-rc.7 and so far everything works just fine wit...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #iex
- #elixirconf-us
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kartheek
Task.await expects task to be passed - you are passing string. You may have to map name to a corresponding task.
hernancuy
I don’t know if I’m doing wrong this name creation so, because the idea here is create a name random, and this name gonna be the name task. This is the string that I’m passing in the code that you see.
Do I need to pass the name like an atom ?
Thank you Kartheek
kartheek
You are welcome @hernancuy .
I don’t think naming a task is possible and your code does not attempt it. It generated name and that name was overwritten by task returned by Task.async.
This is a naive implementation - i only addressed the name to task mapping part of it. Store name against corresponding task which was created in Agent state. Retrieve task for a given name and check if process is alive and await it if it is alive.
hernancuy
Oh, I see!!!, thank you my friend, you give me the light and the idea to do that. Thank you !!!