Last active
March 7, 2016 16:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
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