GenServer.start! and GenServer.start_link!

63 views
Skip to first unread message

Wiebe-Marten Wijnja

unread,
Dec 22, 2016, 1:34:11 PM12/22/16
to elixir-lang-core
Nearly always, when starting a GenServer (or Agent or ...) from a process (so not inside a supervision tree), 
the process doing the starting does not have a reasonable behaviour to continue in the case that the starting fails
(other than to itself crash).

GenServer.start and GenServer.start_link (and Agent.start, Agent.start_link, etc.) return an `{:ok, pid}` tuple. (or `{:error, info}`)

I am wondering if it would be possible to introduce GenServer.start! and GenServer.start_link! (and item for Agent, ...)
that return just the `pid` (and crash on failure).
The main advantage of this is that start and start_link cannot be incorporated into pipelines, as they return a tuple, whereas
the bang-versions would.

Would this be a good idea, or has a conscious choice been made to not include bang-versions of GenServer.start and GenServer.start_link (and variants)?

José Valim

unread,
Dec 22, 2016, 1:41:18 PM12/22/16
to elixir-l...@googlegroups.com
Given most use cases of GenServer/Agent.start_link are to expose similar callbacks through your own modules, I would recommend providing MyApp.Server.start_link! yourself as I don't see many use cases to justify its addition to Elixir.



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
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-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/440b9098-0adf-458e-8f5e-366dcbe9e6c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages