Packages
k8s
0.2.8
2.8.0
2.7.0
2.6.2
2.6.1
2.6.0
2.5.0
2.4.2
2.4.1
2.4.0
2.3.0
2.2.0
2.1.1
2.1.0
2.0.3
2.0.2
2.0.1
2.0.0
2.0.0-rc.6
2.0.0-rc.5
2.0.0-rc.4
2.0.0-rc.3
2.0.0-rc.2
2.0.0-rc.1
2.0.0-rc.0
1.2.1
1.2.0
1.1.10
1.1.9
1.1.8
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.0
1.0.0-rc1
0.5.2
0.5.1
0.5.0
0.5.0-rc.2
0.5.0-rc.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.13
0.2.12
0.2.11
0.2.10
0.2.9
0.2.8
0.2.7
retired
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.3
Kubernetes API Client for Elixir
Current section
Files
Jump to
Current section
Files
lib/k8s/client/runner/async.ex
defmodule K8s.Client.Runner.Async do
@moduledoc """
`K8s.Client` runner to process a batch of operations asynchronously.
"""
alias K8s.Client.Runner.Base
alias K8s.Operation
@doc """
Async run multiple operations. Operations will be returned in same order given.
Operations will not cease in event of failure.
## Example
Get a list of pods, then map each one to an individual `GET` operation:
```elixir
# Get the pods
operation = K8s.Client.list("v1", "Pod", namespace: :all)
{:ok, %{"items" => pods}} = K8s.Client.run(operation, "test-cluster")
# Map each one to an individual `GET` operation.
operations = Enum.map(pods, fn(%{"metadata" => %{"name" => name, "namespace" => ns}}) ->
K8s.Client.get("v1", "Pod", namespace: ns, name: name)
end)
# Get the results asynchronously
results = K8s.Client.Async.run(operations, "test-cluster")
```
"""
@spec run(list(Operation.t()), binary, keyword) :: list({:ok, struct} | {:error, struct})
def run(operations, cluster_name, opts \\ []) do
operations
|> Enum.map(&Task.async(fn -> Base.run(&1, cluster_name, opts) end))
|> Enum.map(&Task.await/1)
end
end