Skip to content

Instantly share code, notes, and snippets.

@vysakh0
Last active March 7, 2016 16:39
Show Gist options
  • Save vysakh0/6b2d000a2f1317a3c611 to your computer and use it in GitHub Desktop.
Save vysakh0/6b2d000a2f1317a3c611 to your computer and use it in GitHub Desktop.
Problem: Get cars from different vendors for a pickup and destination. Given each vendor has set prices for distances/places.
# ...
def index(conn, params) do
model =
Enum.map(vendor_ids, fn(vendor_id) ->
Task.async(fn() ->
Cabs.find_with_fare(params, vendor_id)
# [ %Cab{price: 1, distance: 2},..]
# Does some calculation based on results from different tables.
end)
end)
|> Enum.map(fn(task) ->
Task.await(task)
end)
|> List.flatten
conn
|> render("index.json", model: model)
end
def vendor_ids do
#...
end
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment