A promise library for Elixir.
Pinky promises are composable, even though their underlying machinery uses Elixir processes. Let's see an example:
Pinky.promise(fn -> expensive_computation() end)
|> Pinky.map(fn result -> result + 5 end)
|> Pinky.flat_map(fn result ->
if result > 10 do
Pinky.promise(fn -> nested_computation(result) end)
else
Pinky.rejected("result too low")
end
end)
|> Pinky.extract # <- this call blocks until the whole promise is realized
# => {:ok, <some_result>}
Have a look at the API documentation to see detailed examples of each of the primitives.
The package can be installed by adding pinky
to your list of dependencies in
mix.exs
:
def deps do
[{:pinky, "~> 0.2.0"}]
end