Last active
September 14, 2023 05:42
-
-
Save jhowarth/40df1170d58c046da3315405fec965bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule GCM.PushCollector do | |
use GenStage | |
# Client | |
def push(pid, push_requests) do | |
GenServer.cast(pid, {:push, push_requests}) | |
end | |
# Server | |
def init(_args) do | |
# Run as producer and specify the max amount | |
# of push requests to buffer. | |
{:producer, :ok, buffer_size: @max_buffer_size} | |
end | |
def handle_cast({:push, push_requests}, state) do | |
# Dispatch the push_requests as events. | |
# These will be buffered if there are no consumers ready. | |
{:noreply, push_requests, state} | |
end | |
def handle_demand(_demand, state) do | |
# Do nothing. Events will be dispatched as-is. | |
{:noreply, [], state} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How did you handle
CONNECTION_DRAINING
?