]> Entropealabs - wampex_client.git/commitdiff
add unsubscribe
authorChristopher Coté <chris@entropealabs.com>
Fri, 12 Nov 2021 20:18:22 +0000 (15:18 -0500)
committerChristopher Coté <chris@entropealabs.com>
Fri, 12 Nov 2021 20:18:22 +0000 (15:18 -0500)
lib/client.ex
mix.exs

index 15c5855d35e9a4a7071c5d77534da47b236a4ede..de1266b54edb0d42d591a9a5f2ff41c4584e7e57 100644 (file)
@@ -14,7 +14,7 @@ defmodule Wampex.Client do
   alias Wampex.Roles.Peer.Error
   alias Wampex.Roles.Publisher
   alias Wampex.Roles.Publisher.Publish
-  alias Wampex.Roles.Subscriber.Subscribe
+  alias Wampex.Roles.Subscriber.{Subscribe, Unsubscribe}
 
   @spec start_link(name: atom(), session_data: Sess.t(), reconnect: boolean()) ::
           {:ok, pid()}
@@ -74,6 +74,19 @@ defmodule Wampex.Client do
     end
   end
 
+  @spec unsubscribe(name :: module(), subscription :: Unsubscribe.t(), timeout :: integer()) ::
+          :ok
+  def unsubscribe(name, %Unsubscribe{subscription_id: si} = unsub, timeout \\ 5000) do
+    case sync(name, Subscriber.unsubscribe(unsub), timeout) do
+      :ok ->
+        Registry.unregister(subscriber_registry_name(name), si)
+        :ok
+
+      er ->
+        er
+    end
+  end
+
   @spec register(name :: module(), register :: Register.t(), timeout :: integer()) ::
           {:ok, integer()}
   def register(name, %Register{procedure: p} = reg, timeout \\ 5000) do
diff --git a/mix.exs b/mix.exs
index 3b0125e5cc9c525331bcab80716de99c765d9034..af451a76cdd4bc8915395e161ddde58647b45b30 100644 (file)
--- a/mix.exs
+++ b/mix.exs
@@ -4,7 +4,7 @@ defmodule Wampex.Client.MixProject do
   def project do
     [
       app: :wampex_client,
-      version: "0.1.4",
+      version: "0.1.5",
       elixir: "~> 1.9",
       start_permanent: Mix.env() == :prod,
       elixirc_paths: elixirc_paths(Mix.env()),