mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: require calling optfn() ? / optfn() or {...} for fn optfn() ? {}
This commit is contained in:
@@ -12,22 +12,20 @@ fn main() {
|
||||
println(term.green('client $ws.id ready'))
|
||||
println('Write message and enter to send...')
|
||||
for {
|
||||
line := os.get_line()
|
||||
line := os.get_line()
|
||||
if line == '' {
|
||||
break
|
||||
}
|
||||
ws.write_str(line)
|
||||
}
|
||||
ws.close(1000, 'normal') or {
|
||||
println(term.red('panicing $err'))
|
||||
ws.write_str(line) ?
|
||||
}
|
||||
ws.close(1000, 'normal') or { println(term.red('panicing $err')) }
|
||||
unsafe {
|
||||
ws.free()
|
||||
}
|
||||
}
|
||||
|
||||
fn start_client() ?&websocket.Client {
|
||||
mut ws := websocket.new_client('ws://localhost:30000')?
|
||||
mut ws := websocket.new_client('ws://localhost:30000') ?
|
||||
// mut ws := websocket.new_client('wss://echo.websocket.org:443')?
|
||||
// use on_open_ref if you want to send any reference object
|
||||
ws.on_open(fn (mut ws websocket.Client) ? {
|
||||
@@ -49,12 +47,8 @@ fn start_client() ?&websocket.Client {
|
||||
}
|
||||
})
|
||||
|
||||
ws.connect() or {
|
||||
println(term.red('error on connect: $err'))
|
||||
}
|
||||
|
||||
go ws.listen() or {
|
||||
println(term.red('error on listen $err'))
|
||||
}
|
||||
ws.connect() or { println(term.red('error on connect: $err')) }
|
||||
|
||||
go ws.listen() or { println(term.red('error on listen $err')) }
|
||||
return ws
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user