From 1093c5155bbc196b96d52e1934036e0994f5ac81 Mon Sep 17 00:00:00 2001 From: Sahn Lam Date: Thu, 15 Sep 2022 10:58:12 -0700 Subject: [PATCH] Add valid_send_options/1 (#12) --- lib/manifold.ex | 16 ++++++++++++++++ mix.exs | 2 +- test/manifold_test.exs | 11 +++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/manifold.ex b/lib/manifold.ex index 5d2b2bd..10d0d5f 100644 --- a/lib/manifold.ex +++ b/lib/manifold.ex @@ -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) diff --git a/mix.exs b/mix.exs index 017d7f9..d5221cd 100644 --- a/mix.exs +++ b/mix.exs @@ -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, diff --git a/test/manifold_test.exs b/test/manifold_test.exs index 64578a3..b8c384a 100644 --- a/test/manifold_test.exs +++ b/test/manifold_test.exs @@ -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