From 6a19a13812a84a56f2252e2daa1eba4cb63bceec Mon Sep 17 00:00:00 2001 From: Miccah Date: Wed, 16 Jun 2021 18:08:02 -0500 Subject: [PATCH] vweb: re-enable concurrency and fix the counter example (#10484) --- examples/vweb/vweb_example.v | 10 ++++++++-- vlib/vweb/vweb.v | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/vweb/vweb_example.v b/examples/vweb/vweb_example.v index f9865222d0..40a242ecff 100644 --- a/examples/vweb/vweb_example.v +++ b/examples/vweb/vweb_example.v @@ -9,6 +9,11 @@ const ( struct App { vweb.Context +mut: + state shared State +} + +struct State { mut: cnt int } @@ -29,9 +34,10 @@ pub fn (mut app App) user_endpoint(user string) vweb.Result { } pub fn (mut app App) index() vweb.Result { - app.cnt++ + lock app.state { + app.state.cnt++ + } show := true - // app.text('Hello world from vweb') hello := 'Hello world from vweb' numbers := [1, 2, 3] app.enable_chunked_transfer(40) diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 6599d8175d..70f2432707 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -334,7 +334,7 @@ pub fn run(global_app &T, port int) { // conn: 0 //} mut conn := l.accept() or { panic('accept() failed') } - handle_conn(mut conn, mut request_app) + go handle_conn(mut conn, mut request_app) } }