Skip to content

Instantly share code, notes, and snippets.

@ospaarmann
Last active January 10, 2018 14:21
Show Gist options
  • Save ospaarmann/aeb6dfe7f0a3fc7f8ddb51950436faa1 to your computer and use it in GitHub Desktop.
Save ospaarmann/aeb6dfe7f0a3fc7f8ddb51950436faa1 to your computer and use it in GitHub Desktop.
TweetBufferFiller
defmodule EmojiMap.TweetBufferFiller do
use GenServer
alias EmojiMap.TweetBroadcaster
alias EmojiMap.TweetConsumer
alias EmojiMap.TwitterStream
def start_link(opts \\ []) do
{:ok, pid} = GenServer.start_link(__MODULE__, [], opts)
# And immediately start the buffer filler process.
# I am not sure if this is the best way to handle this.
# Maybe someone can comment on this.
start_buffer_filler()
{:ok, pid}
end
def start_buffer_filler do
GenServer.cast(:tweet_buffer_filler, {:start})
end
## Server Callbacks
def init([]) do
{:ok, []}
end
def handle_cast({:start}, _from) do
TweetBroadcaster.start_link()
TweetConsumer.start_link()
TwitterStream.get_emoji_stream()
|> Stream.map(&TweetBroadcaster.sync_notify(&1))
|> Enum.to_list()
{:noreply, []}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment