Skip to content

Instantly share code, notes, and snippets.

@cadwallion
Created March 13, 2012 20:02
Show Gist options
  • Select an option

  • Save cadwallion/2031207 to your computer and use it in GitHub Desktop.

Select an option

Save cadwallion/2031207 to your computer and use it in GitHub Desktop.
Bidirectional Ruby DNode
require 'dnode'
Client = {
temp: ->(cb) {
tempC = (20.0 + rand() * 10 - 5).round
cb.call(tempC)
}
}
DNode.new(Client).connect(8188) do |remote, conn|
remote.f2 ->(degF) {
puts "#{degF}' F"
exit
}
end
require 'dnode'
Manager = ->(client) {
{
f2: ->(cb) {
tempProc = ->(degC) {
cb.call((degC * 9 / 5 + 32).round)
}
client['temp'].call(tempProc)
}
}
}
DNode.new(Manager).listen(8188)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment