v2 / vlib / x / async / examples / veb / app_lifecycle.v
27 lines · 24 sloc · 496 bytes · 15fb60b77ea6073658aa8355b247f2e1ae03b714
Raw
1import context
2import veb
3import x.async as xasync
4
5fn render_health_response() !string {
6 mut web_ctx := veb.Context{}
7 _ := web_ctx.text('veb ok')
8 if web_ctx.res.status_code != 200 {
9 return error('unexpected veb status')
10 }
11 return web_ctx.res.body
12}
13
14fn main() {
15 mut task := xasync.run[string](fn (mut ctx context.Context) !string {
16 done := ctx.done()
17 select {
18 _ := <-done {
19 return ctx.err()
20 }
21 else {}
22 }
23 return render_health_response()!
24 })!
25
26 println(task.wait()!)
27}
28