glisten/handler
Types
pub type Handler(data) {
Handler(
socket: Socket,
initial_data: data,
loop: LoopFn(HandlerMessage, data),
on_init: Option(fn(Subject(HandlerMessage)) -> Nil),
on_close: Option(fn(Subject(HandlerMessage)) -> Nil),
transport: Transport,
)
}
Constructors
-
Handler( socket: Socket, initial_data: data, loop: LoopFn(HandlerMessage, data), on_init: Option(fn(Subject(HandlerMessage)) -> Nil), on_close: Option(fn(Subject(HandlerMessage)) -> Nil), transport: Transport, )
pub type HandlerFunc(data) =
fn(BitString, LoopState(data)) ->
actor.Next(HandlerMessage, LoopState(data))
All message types that the handler will receive, or that you can send to the handler process
pub type HandlerMessage {
Close
Ready
ReceiveMessage(BitString)
SendMessage(BitBuilder)
Ssl(socket: Port, data: BitString)
SslClosed
Tcp(socket: Port, data: BitString)
TcpClosed
}
Constructors
-
Close
-
Ready
-
ReceiveMessage(BitString)
-
SendMessage(BitBuilder)
-
Ssl(socket: Port, data: BitString)
-
SslClosed
-
Tcp(socket: Port, data: BitString)
-
TcpClosed
pub type LoopFn(message, data) =
fn(HandlerMessage, LoopState(data)) ->
actor.Next(message, LoopState(data))
Functions
pub fn func(handler func: fn(BitString, LoopState(a)) ->
Next(HandlerMessage, LoopState(a))) -> fn(
HandlerMessage,
LoopState(a),
) -> Next(HandlerMessage, LoopState(a))
This helper will generate a TCP handler that will call your handler function with the BitString data in the packet as well as the LoopState, with any associated state data you are maintaining