Created
September 26, 2020 14:23
-
-
Save bboyadao/7abef92408031a1f04a27a085d052a8f to your computer and use it in GitHub Desktop.
display.ex
This file contains 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 MinigameWeb.CustomerLive do | |
use MinigameWeb, :live_view | |
# use KafkaEx.GenConsumer | |
alias KafkaEx.Protocol.Fetch.Message | |
require Logger | |
def mount(_params, _session, socket) do | |
# IO.inspect({__MODULE__, connected: connected?(socket), root_pid: socket.root_pid, self: self()}) | |
stream = KafkaEx.stream("foobar", 0) | |
stream |> Stream.map(fn(msg) -> IO.puts(msg.value) end) | |
socket = assign(socket, query: "", context: %{stream: stream}) | |
{:ok, socket} | |
end | |
def handle_info(:update, socket, context) do | |
a = context.stream |> Stream.map(fn(msg) -> IO.puts(msg.value) end) |> Enum.to_list | |
# IO.inspect(a) | |
{:noreply, assign(socket, stream: a)} | |
end | |
def handle_info(%{event: "new_message", payload: state}, socket) do | |
IO.inspect(state) | |
{:noreply, assign(socket, state)} | |
end | |
def render(assigns) do | |
IO.inspect(assigns) | |
# a = assigns.context.def | |
c = 1..3 | |
~L""" | |
<span class="weather"> | |
</span> | |
<%= for user <- c do %> | |
<pre> | |
<%= user %> | |
</pre> | |
<% end %> | |
""" | |
# stream = KafkaEx.stream("foobar", 0) | |
# Enum.take(stream, 2) | |
end | |
defp have_stream(stream) do | |
stream |> Enum.to_list | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment