abstract class Cannon::Rpc::Connection

Overview

A (network) connection to invoke remote methods. Use a RemoteService instead of using the methods in this class directly.

Direct Known Subclasses

Defined in:

cannon/rpc/connection.cr

Constructors

Instance Method Summary

Class methods inherited from class Object

to_cannon_io(io, value) to_cannon_io

Constructor Detail

def self.new(manager : Manager) #

[View source]

Instance Method Detail

abstract def call_remotely(service_id : UInt32, function_hash : UInt32, arguments : Tuple | Nil, &block : IO -> _) #

Calls the function (through function_hash) on service_id using arguments. Yields an IO when the response was received and must be read from it using Cannon.decode. If a remote error was encountered, the block is not called, and is raised locally.

This method blocks the current Fiber.


[View source]
abstract def call_remotely(service_id : UInt32, function_hash : UInt32, arguments : Tuple | Nil) #

Like #call_remotely, but doesn't request a response. A response is never requested and thus is never received.

Note: This will also silence any error propagation from the remote side back to the local side.

This method does not block the current Fiber.


[View source]
def close #

Closes the connection gracefully (if possible).


[View source]
def manager : Manager #

The Manager used to offer services to the remote side.


[View source]
def on_local_error(&block : Exception -> _) #

Sets a handler called when a locally called method threw an error.


[View source]
def on_remote_error(&block : RemoteError -> _) #

Sets a handler called when a remotely called method threw an error.


[View source]
abstract def release_remote_service(service_id : UInt32) #

Releases the remote service_id


[View source]
def release_service(service_id : UInt32) #

Releases the local service_id, requested by this connection.


[View source]
abstract def run #

Starts a read-loop, blocking the current Fiber.


[View source]
def running? : Bool #

Is the connection running?


[View source]