Skip to content

Instantly share code, notes, and snippets.

@parroty
Created December 28, 2013 05:21
Show Gist options
  • Save parroty/8156315 to your computer and use it in GitHub Desktop.
Save parroty/8156315 to your computer and use it in GitHub Desktop.
defmodule ExFuture.HelperTest do
use ExUnit.Case
use ExFuture
test "future block" do
f = future do
3 * 3
end
assert 9 == value(f)
end
test "parallel map with future/value macro using collection" do
v = [1, 2, 3]
|> Enum.map(future(&(&1 * 2)))
|> Enum.map(&(value(&1)))
assert v == [2, 4, 6]
end
test "map on future for async chaining" do
i = 1
f1 = future(i * 2)
f2 = map(f1, &(&1 * 3))
f3 = map(f2, &(&1 * 4))
assert 24 == value(f3)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment