Add structured coroutines and explicit error handling
This commit is contained in:
parent
de1262b4cf
commit
fe62e81152
31 changed files with 1701 additions and 325 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue