Add structured coroutines and explicit error handling

This commit is contained in:
pavel 2026-08-27 16:26:40 +02:00
commit fe62e81152
31 changed files with 1701 additions and 325 deletions

View file

@ -36,18 +36,6 @@ class EpicControllerImpl(val db: *bun.DB) {
}
}
worker Counter {
var counter = 0
fun getCount(): Int {
return counter
}
fun increment() {
counter += 1
println(counter)
}
}
fun main() {
val postgresDsn = "postgresql://postgres:postgres@localhost/postgres?sslmode=disable"
val sqlDb = sql.OpenDB(
@ -56,21 +44,10 @@ fun main() {
)
)
val db = bun.NewDB(sqlDb, pgdialect.New())
val counter = Counter()
go {
while(true) {
select {
every(1000) -> counter.increment()
}
}
}
val epicController = EpicControllerImpl(db)
fmt.Println("serving http://localhost:8080")
http.HandleFunc("/", epicController.hello)
http.HandleFunc("/bun", epicController.bunHealth)
http.HandleFunc("/bun/users", epicController.bunUsers)
http.HandleFunc("/counter") { w, r ->
fmt.Fprintln(w, "bun users total:", counter.getCount())
}
http.ListenAndServe(":8080", http.DefaultServeMux)
}