Created
July 19, 2016 20:41
-
-
Save almightycouch/6fed5356c60a6ef70a41eea31777fa62 to your computer and use it in GitHub Desktop.
RethinkDB.Connection one producer, three consumers
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
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