Skip to content

Instantly share code, notes, and snippets.

View anuragsoni's full-sized avatar

Anurag Soni anuragsoni

View GitHub Profile
@anuragsoni
anuragsoni / Main.kt
Created September 16, 2022 02:56
Vert.x Web + Kotlin Coroutines
import io.vertx.core.Vertx
import io.vertx.ext.web.Route
import io.vertx.ext.web.Router
import io.vertx.ext.web.RoutingContext
import io.vertx.kotlin.coroutines.CoroutineVerticle
import io.vertx.kotlin.coroutines.await
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
module Trie = struct
type t = { mutable count : int; children : t option Array.t }
let[@inline] empty () = { count = 0; children = Array.make 128 None }
let add buf pos len t =
let rec loop idx t =
if idx > pos + len - 1 then t.count <- t.count + 1
else
let c = Char.lowercase_ascii (Bytes.get buf idx) in
open Opium.Std
open Lwt.Infix
open Websocket
let src = Logs.Src.create "websocket.upgrade_connection"
(* Example from https://github.com/vbmithr/ocaml-websocket/blob/2e7fb23a7c2b7f52f0274db2687e1855c1ac5ae8/test/upgrade_connection.ml *)
let websocket_handler (_, conn) req body =
let open Frame in
Logs_lwt.app ~src (fun m ->