Dynamic Supervisor doc change

30 views
Skip to first unread message

Bruce Tate

unread,
Apr 19, 2023, 8:40:45 AM4/19/23
to elixir-l...@googlegroups.com
I have been going over my notes and noting the places my students have trouble with standard Elixir documentation. One of them is this example code that starts a child for a dynamic supervisor: 

{:ok, agent1} = DynamicSupervisor.start_child(MyApp.DynamicSupervisor, {Agent, fn -> %{} end}) Agent.update(agent1, &Map.put(&1, :key, "value")) Agent.get(agent1, & &1) #=> %{key: "value"} {:ok, agent2} = DynamicSupervisor.start_child(MyApp.DynamicSupervisor, {Agent, fn -> %{} end}) Agent.get(agent2, & &1) #=> %{} DynamicSupervisor.count_children(MyApp.DynamicSupervisor) #=> %{active: 2, specs: 2, supervisors: 0, workers: 2}


This code gives students two problems: 

1. It expresses a concept using an arguably more complex concept, and not a common one: agents. 

2. The child spec is not like typical gen servers because the initial value is a function. 

I propose that we start a stack rather than an agent. Failing that, I propose we label the concepts in the start spec with intermediate variables. 

-bt
--

Regards,
Bruce Tate
CEO

José Valim

unread,
Apr 20, 2023, 2:12:14 AM4/20/23
to elixir-l...@googlegroups.com
I would love to see a PR that tries approach 1. And we can expand from that. :) Thank you.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAFXvW-45ExCPTm%3Ds-YCu1FoVpxeLWuLTt%2BDs6wV7-BzLPLDkGw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages