Packages
pigeon
1.6.0
2.0.1
2.0.0
2.0.0-rc.3
2.0.0-rc.2
2.0.0-rc.1
2.0.0-rc.0
1.6.3
1.6.2
1.6.1
1.6.0
1.5.1
1.5.0
1.4.0
1.3.2
1.3.1
1.3.0
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.1.0-rc.1
1.1.0-rc.0
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
0.13.1
0.13.0
0.12.1
0.12.0
0.11.0
0.10.3
0.10.2
0.10.1
0.10.0
0.9.1
0.9.0
0.8.0
0.7.0
0.6.0
0.5.2
0.5.1
0.5.0
0.4.1
0.4.0
0.3.0
0.2.0
0.1.0
iOS (APNS), Android (FCM), and Amazon Android (ADM) push notifications for Elixir.
Current section
Files
Jump to
Current section
Files
lib/pigeon/connection/notification_queue.ex
defmodule Pigeon.Connection.NotificationQueue do
@moduledoc false
@type queue :: %{required(pos_integer) => {term, (... -> no_return)}}
@doc ~S"""
Returns a new empty queue.
## Examples
iex> new()
%{}
"""
@spec new :: queue
def new, do: %{}
@doc ~S"""
Adds a notification and on_response callback for given `stream_id`.
## Examples
iex> add(%{}, 1, %Pigeon.APNS.Notification{}, nil)
%{1 => {%Pigeon.APNS.Notification{}, nil}}
"""
@spec add(queue, pos_integer, term, term) :: queue
def add(queue, stream_id, notification, on_response) do
Map.put(queue, stream_id, {notification, on_response})
end
@doc ~S"""
Pops a notification and on_response callback for given `stream_id`.
## Examples
iex> queue = %{1 => {%Pigeon.APNS.Notification{}, nil}}
iex> pop(queue, 1)
{{%Pigeon.APNS.Notification{}, nil}, %{}}
iex> queue = %{1 => {%Pigeon.APNS.Notification{}, nil}}
iex> pop(queue, 3)
{nil, %{1 => {%Pigeon.APNS.Notification{}, nil}}}
"""
@spec pop(queue, pos_integer) :: {nil | {term, term}, queue}
def pop(queue, stream_id) do
result = queue[stream_id]
new_queue = Map.delete(queue, stream_id)
{result, new_queue}
end
end