Skip to content

Instantly share code, notes, and snippets.

@aseigo
aseigo / conditional_start.diff
Created August 13, 2018 08:02
Conditional child specs idea sketch
--- a/lib/elixir/lib/supervisor.ex
+++ b/lib/elixir/lib/supervisor.ex
@@ -461,18 +461,25 @@ defmodule Supervisor do
@behaviour Supervisor
@opts unquote(opts)
+ @doc false
+ def should_start?(_arg), do: true
+
@doc false
defmodule Combi do
def time_run(amount \\ 100_000, batch_size \\ 250) do
values = Enum.to_list(1..amount)
Toolbelt.time(fn -> values |> init(batch_size) end) |> IO.inspect(label: "Init took")
batches = values |> init(batch_size)
Toolbelt.time(fn -> next(batches) |> run(0) end) |> IO.inspect(label: "Batching took")
end
def run({:done, _}, count) do
IO.puts("Completed! #{count} batches")