Skip to content

Commit

Permalink
Add typespecs for processor
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsmith committed Nov 24, 2017
1 parent 3255b64 commit 1de5861
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/code_corps/accounts/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ defmodule CodeCorps.Accounts do
|> Repo.update()
end

@spec upload_github_photo_async(User.t) :: User.t | Processor.result
defp upload_github_photo_async(%User{cloudinary_public_id: nil} = user) do
Processor.process(fn -> upload_github_photo(user) end)
end
Expand Down
1 change: 1 addition & 0 deletions lib/code_corps/processor/async.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule CodeCorps.Processor.Async do
@behaviour CodeCorps.Processor

@spec process((() -> any)) :: {:ok, pid}
def process(fun) do
Task.Supervisor.start_child(:background_processor, fn ->
apply(fun, [])
Expand Down
5 changes: 4 additions & 1 deletion lib/code_corps/processor/processor.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
defmodule CodeCorps.Processor do
@processor Application.get_env(:code_corps, :processor)

@callback process(fun :: (() -> any)) :: any
@type result :: {:ok, pid} | any

@callback process(fun :: (() -> any)) :: result

@spec process((() -> any)) :: result
def process(fun) do
@processor.process(fun)
end
Expand Down
1 change: 1 addition & 0 deletions lib/code_corps/processor/sync.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule CodeCorps.Processor.Sync do
@behaviour CodeCorps.Processor

@spec process((() -> any)) :: any
def process(fun) do
apply(fun, [])
end
Expand Down

0 comments on commit 1de5861

Please sign in to comment.