Current section
Files
Jump to
Current section
Files
lib/rain/progress.ex
defmodule Rain.Progress do
defstruct url: "", name: "unknown", total: 0, size: 0
def start_link(url, name) do
Agent.start_link(fn -> %Rain.Progress{url: url, name: name} end)
end
def get(progress) do
Agent.get(progress, &Map.from_struct(&1))
end
def set_total(progress, total) do
Agent.cast(progress, fn struct ->
%{struct | total: total}
end)
end
def progress(progress, size) do
Agent.cast(progress, fn struct ->
%{struct | size: struct.size + size}
end)
end
def stop(progress) do
Agent.stop(progress)
end
end