Skip to content

Commit

Permalink
Add valid_send_options/1 (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
slam authored Sep 15, 2022
1 parent 7db6d24 commit 1093c51
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/manifold.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ defmodule Manifold do

## Client

@spec valid_send_options?(Keyword.t()) :: boolean()
def valid_send_options?(options) when is_list(options) do
valid_options = [
{:send_mode, :offload},
]

# Keywords could have duplicate keys, in which case the first key wins.
Keyword.keys(options)
|> Enum.dedup()
|> Enum.reduce(true, fn key, acc -> acc and {key, options[key]} in valid_options end)
end

def valid_send_options?(_options) do
false
end

@spec send([pid | nil] | pid | nil, term, send_mode: :offload) :: :ok
def send(pid, message, options \\ [])
def send([pid], message, options), do: __MODULE__.send(pid, message, options)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Manifold.Mixfile do
def project do
[
app: :manifold,
version: "1.5.0",
version: "1.5.1",
elixir: "~> 1.5",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
Expand Down
11 changes: 11 additions & 0 deletions test/manifold_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ defmodule ManifoldTest do
use ExUnit.Case
doctest Manifold

test "valid_send_options?" do
assert Manifold.valid_send_options?([])
assert Manifold.valid_send_options?(send_mode: :offload)
assert Manifold.valid_send_options?(send_mode: :offload, send_mode: :bad)

refute Manifold.valid_send_options?(send_mode: :bad, send_mode: :offload)
refute Manifold.valid_send_options?(unknown: :bad)
refute Manifold.valid_send_options?(:junk)
refute Manifold.valid_send_options?({:junk, :junk})
end

test "many pids" do
me = self()
message = :hello
Expand Down

0 comments on commit 1093c51

Please sign in to comment.