Skip to content

Commit

Permalink
gleam format!
Browse files Browse the repository at this point in the history
  • Loading branch information
rawhat committed Dec 19, 2023
1 parent 8b19b89 commit 1308eaf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 31 deletions.
13 changes: 5 additions & 8 deletions examples/echo_server/src/echo_server.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import glisten.{Packet}

pub fn main() {
let assert Ok(_) =
glisten.handler(
fn() { #(Nil, None) },
fn(msg, state, conn) {
let assert Packet(msg) = msg
let assert Ok(_) = glisten.send(conn, bit_builder.from_bit_string(msg))
actor.continue(state)
},
)
glisten.handler(fn() { #(Nil, None) }, fn(msg, state, conn) {
let assert Packet(msg) = msg
let assert Ok(_) = glisten.send(conn, bit_builder.from_bit_string(msg))
actor.continue(state)
})
|> glisten.serve(3000)

process.sleep_forever()
Expand Down
15 changes: 6 additions & 9 deletions src/glisten.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,12 @@ pub opaque type Handler(user_message, data) {
fn map_user_selector(
selector: Selector(Message(user_message)),
) -> Selector(handler.LoopMessage(user_message)) {
process.map_selector(
selector,
fn(value) {
case value {
Packet(msg) -> handler.Packet(msg)
User(msg) -> handler.Custom(msg)
}
},
)
process.map_selector(selector, fn(value) {
case value {
Packet(msg) -> handler.Packet(msg)
User(msg) -> handler.Custom(msg)
}
})
}

fn convert_loop(
Expand Down
15 changes: 6 additions & 9 deletions test/glisten_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,12 @@ pub fn it_echoes_messages_test() {
pub fn it_accepts_from_the_pool_test() {
let client_sender = process.new_subject()
let assert Ok(Nil) =
glisten.handler(
fn() { #(Nil, None) },
fn(msg, state, conn) {
let assert Packet(msg) = msg
let assert Ok(_) =
tcp.send(conn.socket, bytes_builder.from_bit_array(msg))
actor.continue(state)
},
)
glisten.handler(fn() { #(Nil, None) }, fn(msg, state, conn) {
let assert Packet(msg) = msg
let assert Ok(_) =
tcp.send(conn.socket, bytes_builder.from_bit_array(msg))
actor.continue(state)
})
|> glisten.with_pool_size(1)
|> glisten.serve(9998)

Expand Down
8 changes: 3 additions & 5 deletions test/tcp_client.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ fn tcp_connect(

pub fn connect(port: Int) -> Socket {
let assert Ok(client) =
tcp_connect(
charlist.from_string("localhost"),
port,
[dynamic.from(atom.create_from_string("binary"))],
)
tcp_connect(charlist.from_string("localhost"), port, [
dynamic.from(atom.create_from_string("binary")),
])
client
}

0 comments on commit 1308eaf

Please sign in to comment.