diff options
author | Hubert Chathi <hubert@uhoreg.ca> | 2020-08-21 23:07:10 -0400 |
---|---|---|
committer | Hubert Chathi <hubert@uhoreg.ca> | 2020-08-21 23:07:10 -0400 |
commit | 68ccfefec146c3938c18babfb22df690f350b356 (patch) | |
tree | bc80556d69a4a326799b11ca428d4d55e74cf84a /lib/polyjuice/client.ex | |
parent | automatically start/stop sync when logging in/out (diff) |
execute room requests in a queue
Diffstat (limited to 'lib/polyjuice/client.ex')
-rw-r--r-- | lib/polyjuice/client.ex | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/polyjuice/client.ex b/lib/polyjuice/client.ex index 6cf1c84..39cadf0 100644 --- a/lib/polyjuice/client.ex +++ b/lib/polyjuice/client.ex @@ -178,6 +178,18 @@ defmodule Polyjuice.Client do def call(client_api, endpoint) @doc """ + Execute a function in a queue for a room. + + This is to make sure that, for example, messages are sent in order. + """ + @spec room_queue( + client_api :: Polyjuice.Client.API.t(), + room_id :: String.t(), + func :: function + ) :: any + def room_queue(client_api, room_id, func) + + @doc """ Generate a unique transaction ID. """ @spec transaction_id(client_api :: Polyjuice.Client.API.t()) :: String.t() @@ -244,6 +256,10 @@ defmodule Polyjuice.Client do end end + def room_queue(%{id: id}, room_id, func) when is_binary(room_id) and is_function(func) do + Mutex.under(Polyjuice.Client.Mutex, {id, room_id}, func) + end + def transaction_id(_) do "#{Node.self()}_#{:erlang.system_time(:millisecond)}_#{:erlang.unique_integer()}" end |