Skip to content

Commit

Permalink
Invoke event handler when connection is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
joncol committed Oct 30, 2015
1 parent f028f24 commit f7ca79c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/rjr/nodes/tcp.rb
Expand Up @@ -54,6 +54,9 @@ def send_msg(data)
}
end

def unbind
@rjr_node.send(:connection_event, :closed)
end
end

# TCP node definition, listen for and invoke json-rpc requests via TCP sockets
Expand Down
12 changes: 11 additions & 1 deletion specs/nodes/tcp_spec.rb
Expand Up @@ -64,9 +64,19 @@ module RJR::Nodes
res.should == nil
end
end

describe "closed event handler" do
it "should be invoked when connection is closed" do
handler_invoked = false
server.on(:closed) { |node| handler_invoked = true }
client.invoke 'jsonrpc://localhost:9987', 'foobar', 'myparam'
server.halt.join
handler_invoked.should be_truthy
end
end
end

# TODO test callbacks over tcp interface
# TODO ensure closed / error event handlers are invoked
# TODO ensure error event handler is invoked
end
end

0 comments on commit f7ca79c

Please sign in to comment.