Skip to content

Commit 6a19a13

Browse files
authored
vweb: re-enable concurrency and fix the counter example (#10484)
1 parent ae014ad commit 6a19a13

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

examples/vweb/vweb_example.v

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ const (
99

1010
struct App {
1111
vweb.Context
12+
mut:
13+
state shared State
14+
}
15+
16+
struct State {
1217
mut:
1318
cnt int
1419
}
@@ -29,9 +34,10 @@ pub fn (mut app App) user_endpoint(user string) vweb.Result {
2934
}
3035

3136
pub fn (mut app App) index() vweb.Result {
32-
app.cnt++
37+
lock app.state {
38+
app.state.cnt++
39+
}
3340
show := true
34-
// app.text('Hello world from vweb')
3541
hello := 'Hello world from vweb'
3642
numbers := [1, 2, 3]
3743
app.enable_chunked_transfer(40)

vlib/vweb/vweb.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ pub fn run<T>(global_app &T, port int) {
334334
// conn: 0
335335
//}
336336
mut conn := l.accept() or { panic('accept() failed') }
337-
handle_conn<T>(mut conn, mut request_app)
337+
go handle_conn<T>(mut conn, mut request_app)
338338
}
339339
}
340340

0 commit comments

Comments
 (0)