Skip to content

Instantly share code, notes, and snippets.

@almightycouch
Created July 19, 2016 20:41
Show Gist options
  • Save almightycouch/6fed5356c60a6ef70a41eea31777fa62 to your computer and use it in GitHub Desktop.
Save almightycouch/6fed5356c60a6ef70a41eea31777fa62 to your computer and use it in GitHub Desktop.
RethinkDB.Connection one producer, three consumers
import RethinkDB.Query
require Logger
{:ok, pid} = RethinkDB.Connection.start_link
for i <- 1..3 do
spawn_link fn ->
Logger.debug "#{i} started"
{:ok, feed} = table("users")
|> changes
|> RethinkDB.run(pid)
feed
|> Stream.each(fn change -> Logger.debug "#{i} => #{inspect change}" end)
|> Stream.run
end
end
1_000
|> Stream.interval
|> Enum.each(fn _i ->
table("users")
|> insert(%{name: "Lia", age: 23, in_relationship: true})
|> RethinkDB.run(pid)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment