fmt: replace go with spawn

This commit is contained in:
Alexander Medvednikov 2022-11-05 10:46:40 +03:00
parent a082328e40
commit e81e0ac708
126 changed files with 262 additions and 262 deletions

View file

@ -298,7 +298,7 @@ pub fn (mut ts TestSession) test() {
ts.nmessages = chan LogMessage{cap: 10000} ts.nmessages = chan LogMessage{cap: 10000}
ts.nprint_ended = chan int{cap: 0} ts.nprint_ended = chan int{cap: 0}
ts.nmessage_idx = 0 ts.nmessage_idx = 0
go ts.print_messages() spawn ts.print_messages()
pool_of_test_runners.set_shared_context(ts) pool_of_test_runners.set_shared_context(ts)
pool_of_test_runners.work_on_pointers(unsafe { remaining_files.pointers() }) pool_of_test_runners.work_on_pointers(unsafe { remaining_files.pointers() })
ts.benchmark.stop() ts.benchmark.stop()

View file

@ -73,7 +73,7 @@ fn main() {
if ctx.is_verbose { if ctx.is_verbose {
eprintln('> args: $args | context: $ctx') eprintln('> args: $args | context: $ctx')
} }
go do_timeout(&ctx) spawn do_timeout(&ctx)
for i := 1; true; i++ { for i := 1; true; i++ {
ctx.println('$i') ctx.println('$i')
time.sleep(ctx.period_ms * time.millisecond) time.sleep(ctx.period_ms * time.millisecond)

View file

@ -210,7 +210,7 @@ fn (vd VDoc) render_parallel(out Output) {
work.close() work.close()
wg.add(vjobs) wg.add(vjobs)
for _ in 0 .. vjobs { for _ in 0 .. vjobs {
go vd.work_processor(mut work, mut wg) spawn vd.work_processor(mut work, mut wg)
} }
wg.wait() wg.wait()
} }

View file

@ -57,7 +57,7 @@ fn main() {
mut source := os.read_file(context.path)! mut source := os.read_file(context.path)!
source = source[..context.cut_index] source = source[..context.cut_index]
go fn (ms int) { spawn fn (ms int) {
time.sleep(ms * time.millisecond) time.sleep(ms * time.millisecond)
exit(ecode_timeout) exit(ecode_timeout)
}(context.timeout_ms) }(context.timeout_ms)
@ -248,7 +248,7 @@ fn (mut context Context) start_printing() {
if !context.is_linear && !context.is_silent { if !context.is_linear && !context.is_silent {
println('\n') println('\n')
} }
go context.print_periodic_status() spawn context.print_periodic_status()
} }
fn (mut context Context) stop_printing() { fn (mut context Context) stop_printing() {

View file

@ -381,6 +381,6 @@ fn (mut context Context) worker_main() {
context.is_exiting = true context.is_exiting = true
context.kill_pgroup() context.kill_pgroup()
}) or { panic(err) } }) or { panic(err) }
go context.compilation_runner_loop() spawn context.compilation_runner_loop()
change_detection_loop(context) change_detection_loop(context)
} }

View file

@ -9,9 +9,9 @@ fn expensive_computing(id int, duration int) {
fn main() { fn main() {
mut threads := []thread{} mut threads := []thread{}
threads << go expensive_computing(1, 100) threads << spawn expensive_computing(1, 100)
threads << go expensive_computing(2, 500) threads << spawn expensive_computing(2, 500)
threads << go expensive_computing(3, 1000) threads << spawn expensive_computing(3, 1000)
// Join all tasks // Join all tasks
threads.wait() threads.wait()
println('All jobs finished!') println('All jobs finished!')

View file

@ -26,7 +26,7 @@ fn main() {
mut wg := sync.new_waitgroup() mut wg := sync.new_waitgroup()
wg.add(2) wg.add(2)
// Run tasks async // Run tasks async
go vlang_time(mut wg) spawn vlang_time(mut wg)
go remote_ip(mut wg) spawn remote_ip(mut wg)
wg.wait() wg.wait()
} }

View file

@ -5,7 +5,7 @@ fn expensive_computing(i int) int {
fn main() { fn main() {
mut threads := []thread int{} mut threads := []thread int{}
for i in 1 .. 10 { for i in 1 .. 10 {
threads << go expensive_computing(i) threads << spawn expensive_computing(i)
} }
// Join all tasks // Join all tasks
r := threads.wait() r := threads.wait()

View file

@ -198,7 +198,7 @@ fn main() {
network: [2, 2, 1] network: [2, 2, 1]
} }
app.start() app.start()
go app.run() spawn app.run()
app.gg.run() app.gg.run()
} }

View file

@ -58,7 +58,7 @@ fn (mut state AppState) update() {
threads.wait() threads.wait()
} }
for t in 0 .. state.ntasks { for t in 0 .. state.ntasks {
threads << go state.worker(t, chunk_channel, chunk_ready_channel) threads << spawn state.worker(t, chunk_channel, chunk_ready_channel)
} }
// //
mut oview := ViewRect{} mut oview := ViewRect{}
@ -237,6 +237,6 @@ fn main() {
scroll_fn: graphics_scroll scroll_fn: graphics_scroll
user_data: state user_data: state
) )
go state.update() spawn state.update()
state.gg.run() state.gg.run()
} }

View file

@ -58,6 +58,6 @@ fn main() {
frame_fn: graphics_frame frame_fn: graphics_frame
user_data: state user_data: state
) )
go state.update() spawn state.update()
state.gg.run() state.gg.run()
} }

View file

@ -42,7 +42,7 @@ fn main() {
fn init(mut app App) { fn init(mut app App) {
// Spawn a new worker thread. // Spawn a new worker thread.
go worker(mut app) spawn worker(mut app)
} }
// worker simulates a workload. This should be run in a separate thread. // worker simulates a workload. This should be run in a separate thread.

View file

@ -45,7 +45,7 @@ fn main() {
) )
// window.onkeydown(key_down) // window.onkeydown(key_down)
println('Starting the game loop...') println('Starting the game loop...')
go game.run() spawn game.run()
game.gg.run() game.gg.run()
} }

View file

@ -15,7 +15,7 @@ fn main() {
mut wg := sync.new_waitgroup() mut wg := sync.new_waitgroup()
for i := 0; i < 50; i++ { for i := 0; i < 50; i++ {
wg.add(1) wg.add(1)
go send_request(mut wg) spawn send_request(mut wg)
} }
wg.wait() wg.wait()
} }

View file

@ -24,14 +24,14 @@ fn main() {
} }
for id in 0 .. args.workers { for id in 0 .. args.workers {
workers << go sim.sim_worker(id, app.request_chan, [app.result_chan]) workers << spawn sim.sim_worker(id, app.request_chan, [app.result_chan])
} }
handle_request := fn [app] (request &sim.SimRequest) ! { handle_request := fn [app] (request &sim.SimRequest) ! {
app.request_chan <- request app.request_chan <- request
} }
go app.gg.run() spawn app.gg.run()
sim.run(args.params, grid: args.grid, on_request: sim.SimRequestHandler(handle_request)) sim.run(args.params, grid: args.grid, on_request: sim.SimRequestHandler(handle_request))
} }

View file

@ -38,16 +38,16 @@ fn main() {
// start a worker on each core // start a worker on each core
for id in 0 .. app.args.workers { for id in 0 .. app.args.workers {
workers << go sim.sim_worker(id, app.request_chan, [app.result_chan, img_result_chan]) workers << spawn sim.sim_worker(id, app.request_chan, [app.result_chan, img_result_chan])
} }
handle_request := fn [app] (request &sim.SimRequest) ! { handle_request := fn [app] (request &sim.SimRequest) ! {
app.request_chan <- request app.request_chan <- request
} }
workers << go img.image_worker(mut writer, img_result_chan, img_settings) workers << spawn img.image_worker(mut writer, img_result_chan, img_settings)
go app.gg.run() spawn app.gg.run()
sim.run(app.args.params, sim.run(app.args.params,
grid: app.args.grid grid: app.args.grid

View file

@ -48,7 +48,7 @@ pub fn new_app(args simargs.ParallelArgs) &App {
fn init(mut app App) { fn init(mut app App) {
app.iidx = app.gg.new_streaming_image(app.args.grid.width, app.args.grid.height, 4, app.iidx = app.gg.new_streaming_image(app.args.grid.width, app.args.grid.height, 4,
pixel_format: .rgba8) pixel_format: .rgba8)
go pixels_worker(mut app) spawn pixels_worker(mut app)
} }
fn frame(mut app App) { fn frame(mut app App) {

View file

@ -35,7 +35,7 @@ fn main() {
} }
for id in 0 .. args.workers { for id in 0 .. args.workers {
workers << go sim.sim_worker(id, request_chan, [result_chan]) workers << spawn sim.sim_worker(id, request_chan, [result_chan])
} }
mut x := 0 mut x := 0

View file

@ -34,10 +34,10 @@ fn main() {
} }
for id in 0 .. args.workers { for id in 0 .. args.workers {
workers << go sim.sim_worker(id, request_chan, [result_chan]) workers << spawn sim.sim_worker(id, request_chan, [result_chan])
} }
workers << go img.image_worker(mut writer, result_chan, img_settings) workers << spawn img.image_worker(mut writer, result_chan, img_settings)
handle_request := fn [request_chan] (request &sim.SimRequest) ! { handle_request := fn [request_chan] (request &sim.SimRequest) ! {
request_chan <- request request_chan <- request

View file

@ -129,7 +129,7 @@ fn main() {
) )
app.qt = app.qt.create(0, 0, 1340, 640, 8, 4, 0) app.qt = app.qt.create(0, 0, 1340, 640, 8, 4, 0)
app.start() app.start()
go app.run() spawn app.run()
app.gg.run() app.gg.run()
} }

View file

@ -14,7 +14,7 @@ fn main() {
eprintln('Listen on $laddr ...') eprintln('Listen on $laddr ...')
for { for {
mut socket := server.accept()! mut socket := server.accept()!
go handle_client(mut socket) spawn handle_client(mut socket)
} }
} }

View file

@ -49,6 +49,6 @@ fn start_client() !&websocket.Client {
ws.connect() or { println(term.red('error on connect: $err')) } ws.connect() or { println(term.red('error on connect: $err')) }
go ws.listen() // or { println(term.red('error on listen $err')) } spawn ws.listen() // or { println(term.red('error on listen $err')) }
return ws return ws
} }

View file

@ -4,7 +4,7 @@ import time
import net.websocket import net.websocket
fn main() { fn main() {
go start_server() spawn start_server()
time.sleep(100 * time.millisecond) time.sleep(100 * time.millisecond)
start_client()! start_client()!
} }
@ -65,7 +65,7 @@ fn start_client() ! {
// // println('type: $msg.opcode payload:\n$msg.payload ref: $r') // // println('type: $msg.opcode payload:\n$msg.payload ref: $r')
// }, &r) // }, &r)
ws.connect() or { println('error on connect: $err') } ws.connect() or { println('error on connect: $err') }
go write_echo(mut ws) // or { println('error on write_echo $err') } spawn write_echo(mut ws) // or { println('error on write_echo $err') }
ws.listen() or { println('error on listen $err') } ws.listen() or { println('error on listen $err') }
unsafe { unsafe {
ws.free() ws.free()

View file

@ -195,7 +195,7 @@ fn new_x11_clipboard(selection AtomType) &Clipboard {
cb.selection = cb.get_atom(selection) cb.selection = cb.get_atom(selection)
// start the listener on another thread or // start the listener on another thread or
// we will be locked and will have to hard exit // we will be locked and will have to hard exit
go cb.start_listener() spawn cb.start_listener()
return cb return cb
} }

View file

@ -141,7 +141,7 @@ fn propagate_cancel(mut parent Context, mut child Canceler) {
} }
} }
mut p := parent_cancel_context(mut parent) or { mut p := parent_cancel_context(mut parent) or {
go fn (mut parent Context, mut child Canceler) { spawn fn (mut parent Context, mut child Canceler) {
pdone := parent.done() pdone := parent.done()
select { select {
_ := <-pdone { _ := <-pdone {

View file

@ -13,7 +13,7 @@ fn test_with_cancel() {
// the internal routine started by gen. // the internal routine started by gen.
gen := fn (mut ctx context.Context) chan int { gen := fn (mut ctx context.Context) chan int {
dst := chan int{} dst := chan int{}
go fn (mut ctx context.Context, dst chan int) { spawn fn (mut ctx context.Context, dst chan int) {
mut v := 0 mut v := 0
ch := ctx.done() ch := ctx.done()
for { for {

View file

@ -51,7 +51,7 @@ pub fn with_deadline(mut parent Context, d time.Time) (Context, CancelFn) {
} }
if ctx.err() is none { if ctx.err() is none {
go fn (mut ctx TimerContext, dur time.Duration) { spawn fn (mut ctx TimerContext, dur time.Duration) {
time.sleep(dur) time.sleep(dur)
ctx.cancel(true, deadline_exceeded) ctx.cancel(true, deadline_exceeded)
}(mut ctx, dur) }(mut ctx, dur)

View file

@ -30,7 +30,7 @@ pub fn merge(ctx context.Context, ctxs ...context.Context) (context.Context, con
cancel_fn: cancel cancel_fn: cancel
cancel_ctx: cancel_ctx cancel_ctx: cancel_ctx
} }
go octx.run() spawn octx.run()
return context.Context(octx), context.CancelFn(cancel) return context.Context(octx), context.CancelFn(cancel)
} }
@ -112,7 +112,7 @@ pub fn (mut octx OneContext) cancel(err IError) {
} }
pub fn (mut octx OneContext) run_two_contexts(mut ctx1 context.Context, mut ctx2 context.Context) { pub fn (mut octx OneContext) run_two_contexts(mut ctx1 context.Context, mut ctx2 context.Context) {
go fn (mut octx OneContext, mut ctx1 context.Context, mut ctx2 context.Context) { spawn fn (mut octx OneContext, mut ctx1 context.Context, mut ctx2 context.Context) {
octx_cancel_done := octx.cancel_ctx.done() octx_cancel_done := octx.cancel_ctx.done()
c1done := ctx1.done() c1done := ctx1.done()
c2done := ctx2.done() c2done := ctx2.done()
@ -131,7 +131,7 @@ pub fn (mut octx OneContext) run_two_contexts(mut ctx1 context.Context, mut ctx2
} }
pub fn (mut octx OneContext) run_multiple_contexts(mut ctx context.Context) { pub fn (mut octx OneContext) run_multiple_contexts(mut ctx context.Context) {
go fn (mut octx OneContext, mut ctx context.Context) { spawn fn (mut octx OneContext, mut ctx context.Context) {
octx_cancel_done := octx.cancel_ctx.done() octx_cancel_done := octx.cancel_ctx.done()
cdone := ctx.done() cdone := ctx.done()
select { select {

View file

@ -63,7 +63,7 @@ fn test_log_mutable_reference() {
println(@FN + ' start') println(@FN + ' start')
mut log := new_log() mut log := new_log()
assert typeof(log).name == '&log.Log' assert typeof(log).name == '&log.Log'
go log_mutable_statements(mut log) spawn log_mutable_statements(mut log)
delay() // wait to finish delay() // wait to finish
assert true assert true
println(@FN + ' end') println(@FN + ' end')
@ -75,7 +75,7 @@ fn test_logger_mutable_reference() {
mut logger := new_log_as_logger() mut logger := new_log_as_logger()
logger.set_level(.warn) logger.set_level(.warn)
assert typeof(logger).name == '&log.Logger' assert typeof(logger).name == '&log.Logger'
go logger_mutable_statements(mut logger) spawn logger_mutable_statements(mut logger)
delay() // wait to finish delay() // wait to finish
assert true assert true
println(@FN + ' end') println(@FN + ' end')

View file

@ -5,7 +5,7 @@ fn test_server_stop() {
mut server := &http.Server{ mut server := &http.Server{
accept_timeout: 1 * time.second accept_timeout: 1 * time.second
} }
t := go server.listen_and_serve() t := spawn server.listen_and_serve()
time.sleep(250 * time.millisecond) time.sleep(250 * time.millisecond)
mut watch := time.new_stopwatch() mut watch := time.new_stopwatch()
server.stop() server.stop()
@ -20,7 +20,7 @@ fn test_server_close() {
accept_timeout: 1 * time.second accept_timeout: 1 * time.second
handler: MyHttpHandler{} handler: MyHttpHandler{}
} }
t := go server.listen_and_serve() t := spawn server.listen_and_serve()
time.sleep(250 * time.millisecond) time.sleep(250 * time.millisecond)
mut watch := time.new_stopwatch() mut watch := time.new_stopwatch()
server.close() server.close()
@ -67,7 +67,7 @@ fn test_server_custom_handler() {
handler: handler handler: handler
port: cport port: cport
} }
t := go server.listen_and_serve() t := spawn server.listen_and_serve()
for server.status() != .running { for server.status() != .running {
time.sleep(10 * time.millisecond) time.sleep(10 * time.millisecond)
} }

View file

@ -67,7 +67,7 @@ fn start_server(schannel chan int, shared ctx Context) {
} }
continue continue
} }
go receive_data(mut tcp_con, shared ctx) spawn receive_data(mut tcp_con, shared ctx)
lock ctx { lock ctx {
ctx.ok_server_accepts++ ctx.ok_server_accepts++
} }
@ -109,11 +109,11 @@ fn test_tcp_self_dialing() {
start_time := time.now() start_time := time.now()
shared ctx := &Context{} shared ctx := &Context{}
mut server_channel := chan int{cap: 1} mut server_channel := chan int{cap: 1}
go start_server(server_channel, shared ctx) spawn start_server(server_channel, shared ctx)
svalue := <-server_channel svalue := <-server_channel
elog('>>> server was started: ${svalue}. Starting clients:') elog('>>> server was started: ${svalue}. Starting clients:')
for i := int(0); i < 20; i++ { for i := int(0); i < 20; i++ {
go start_client(i, shared ctx) spawn start_client(i, shared ctx)
elog('>>> started client $i') elog('>>> started client $i')
// time.sleep(2 * time.millisecond) // time.sleep(2 * time.millisecond)
} }

View file

@ -14,7 +14,7 @@ fn setup() (&net.TcpListener, &net.TcpConn, &net.TcpConn) {
mut server := net.listen_tcp(.ip6, server_port) or { panic(err) } mut server := net.listen_tcp(.ip6, server_port) or { panic(err) }
c := chan &net.TcpConn{} c := chan &net.TcpConn{}
go accept(mut server, c) spawn accept(mut server, c)
mut client := net.dial_tcp('localhost$server_port') or { panic(err) } mut client := net.dial_tcp('localhost$server_port') or { panic(err) }
socket := <-c socket := <-c

View file

@ -64,7 +64,7 @@ fn test_tcp_ip6() {
fn start_echo_server(mut l net.TcpListener) { fn start_echo_server(mut l net.TcpListener) {
ch_server_started := chan int{} ch_server_started := chan int{}
go one_shot_echo_server(mut l, ch_server_started) spawn one_shot_echo_server(mut l, ch_server_started)
_ := <-ch_server_started _ := <-ch_server_started
} }

View file

@ -54,7 +54,7 @@ fn echo() ! {
fn test_udp() { fn test_udp() {
mut l := net.listen_udp(server_addr) or { panic('could not listen_udp: $err') } mut l := net.listen_udp(server_addr) or { panic('could not listen_udp: $err') }
go echo_server(mut l) spawn echo_server(mut l)
echo() or { panic('could not echo: $err') } echo() or { panic('could not echo: $err') }
l.close() or {} l.close() or {}

View file

@ -30,7 +30,7 @@ fn handle_conn(mut c unix.StreamConn) {
fn echo_server(mut l unix.StreamListener) ! { fn echo_server(mut l unix.StreamListener) ! {
for { for {
mut new_conn := l.accept() or { continue } mut new_conn := l.accept() or { continue }
go handle_conn(mut new_conn) spawn handle_conn(mut new_conn)
} }
} }
@ -54,7 +54,7 @@ fn echo() ! {
fn test_tcp() { fn test_tcp() {
assert os.exists(test_port) == false assert os.exists(test_port) == false
mut l := unix.listen_stream(test_port) or { panic(err) } mut l := unix.listen_stream(test_port) or { panic(err) }
go echo_server(mut l) spawn echo_server(mut l)
echo() or { panic(err) } echo() or { panic(err) }
l.close() or {} l.close() or {}
} }

View file

@ -19,7 +19,7 @@ fn testsuite_end() {
fn test_that_net_and_net_unix_can_be_imported_together_without_conflicts() { fn test_that_net_and_net_unix_can_be_imported_together_without_conflicts() {
mut l := unix.listen_stream(test_port) or { panic(err) } mut l := unix.listen_stream(test_port) or { panic(err) }
go echo_server(mut l) spawn echo_server(mut l)
defer { defer {
l.close() or {} l.close() or {}
} }

View file

@ -64,10 +64,10 @@ pub fn (mut s Server) listen() ! {
s.logger.info('websocket server: start listen on port $s.port') s.logger.info('websocket server: start listen on port $s.port')
s.ls = net.listen_tcp(s.family, ':$s.port')! s.ls = net.listen_tcp(s.family, ':$s.port')!
s.set_state(.open) s.set_state(.open)
go s.handle_ping() spawn s.handle_ping()
for { for {
mut c := s.accept_new_client() or { continue } mut c := s.accept_new_client() or { continue }
go s.serve_client(mut c) spawn s.serve_client(mut c)
} }
s.logger.info('websocket server: end listen on port $s.port') s.logger.info('websocket server: end listen on port $s.port')
} }

View file

@ -27,7 +27,7 @@ fn test_ws_ipv6() {
} }
port := 30000 + rand.intn(1024) or { 0 } port := 30000 + rand.intn(1024) or { 0 }
eprintln('> port ipv6: $port') eprintln('> port ipv6: $port')
go start_server(.ip6, port) spawn start_server(.ip6, port)
time.sleep(1500 * time.millisecond) time.sleep(1500 * time.millisecond)
ws_test(.ip6, 'ws://localhost:$port') or { ws_test(.ip6, 'ws://localhost:$port') or {
eprintln('> error while connecting .ip6, err: $err') eprintln('> error while connecting .ip6, err: $err')
@ -42,7 +42,7 @@ fn test_ws_ipv4() {
} }
port := 30000 + rand.intn(1024) or { 0 } port := 30000 + rand.intn(1024) or { 0 }
eprintln('> port ipv4: $port') eprintln('> port ipv4: $port')
go start_server(.ip, port) spawn start_server(.ip, port)
time.sleep(1500 * time.millisecond) time.sleep(1500 * time.millisecond)
ws_test(.ip, 'ws://localhost:$port') or { ws_test(.ip, 'ws://localhost:$port') or {
eprintln('> error while connecting .ip, err: $err') eprintln('> error while connecting .ip, err: $err')
@ -113,7 +113,7 @@ fn ws_test(family net.AddrFamily, uri string) ! {
} }
}, test_results) }, test_results)
ws.connect() or { panic('fail to connect, err: $err') } ws.connect() or { panic('fail to connect, err: $err') }
go ws.listen() spawn ws.listen()
text := ['a'].repeat(2) text := ['a'].repeat(2)
for msg in text { for msg in text {
ws.write(msg.bytes(), .text_frame) or { panic('fail to write to websocket, err: $err') } ws.write(msg.bytes(), .text_frame) or { panic('fail to write to websocket, err: $err') }

View file

@ -240,7 +240,7 @@ pub fn new(config Config) &Picoev {
} }
C.picoev_add(voidptr(loop), fd, int(Event.read), 0, accept_callback, pv) C.picoev_add(voidptr(loop), fd, int(Event.read), 0, accept_callback, pv)
go update_date(mut pv) spawn update_date(mut pv)
return pv return pv
} }

View file

@ -38,7 +38,7 @@ fn main() {
mut no := nobj mut no := nobj
for i in 0 .. nrec { for i in 0 .. nrec {
n := no / (nrec - i) n := no / (nrec - i)
go do_rec(ch, resch, n) spawn do_rec(ch, resch, n)
no -= n no -= n
} }
$if debug { $if debug {
@ -49,7 +49,7 @@ fn main() {
n := no / (nsend - i) n := no / (nsend - i)
end := no end := no
no -= n no -= n
go do_send(ch, no, end) spawn do_send(ch, no, end)
} }
assert no == 0 assert no == 0
mut sum := i64(0) mut sum := i64(0)

View file

@ -117,11 +117,11 @@ fn main() {
} }
ctx.pops_wg.add(n_readers) ctx.pops_wg.add(n_readers)
for i := 0; i < n_readers; i++ { for i := 0; i < n_readers; i++ {
go do_rec(ch, i, mut ctx) spawn do_rec(ch, i, mut ctx)
} }
ctx.pushes_wg.add(n_writers) ctx.pushes_wg.add(n_writers)
for i := 0; i < n_writers; i++ { for i := 0; i < n_writers; i++ {
go do_send(ch, i, mut ctx) spawn do_send(ch, i, mut ctx)
} }
ctx.pushes_wg.wait() ctx.pushes_wg.wait()
eprintln('>> all pushes done') eprintln('>> all pushes done')

View file

@ -10,7 +10,7 @@ fn do_send(ch chan int) {
fn test_channel_buffered() { fn test_channel_buffered() {
ch := chan int{cap: 1000} ch := chan int{cap: 1000}
go do_send(ch) spawn do_send(ch)
mut sum := i64(0) mut sum := i64(0)
for _ in 0 .. num_iterations { for _ in 0 .. num_iterations {
sum += <-ch sum += <-ch

View file

@ -10,7 +10,7 @@ fn do_send(ch chan int) {
fn test_channel_unbuffered() { fn test_channel_unbuffered() {
ch := chan int{} ch := chan int{}
go do_send(ch) spawn do_send(ch)
mut sum := i64(0) mut sum := i64(0)
for _ in 0 .. num_iterations { for _ in 0 .. num_iterations {
sum += <-ch sum += <-ch

View file

@ -16,14 +16,14 @@ fn do_send(ch chan int) {
fn test_channel_multi_unbuffered() { fn test_channel_multi_unbuffered() {
ch := chan int{} ch := chan int{}
resch := chan i64{} resch := chan i64{}
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_send(ch) spawn do_send(ch)
go do_send(ch) spawn do_send(ch)
go do_send(ch) spawn do_send(ch)
go do_send(ch) spawn do_send(ch)
mut sum := i64(0) mut sum := i64(0)
for _ in 0 .. 4 { for _ in 0 .. 4 {
sum += <-resch sum += <-resch

View file

@ -16,14 +16,14 @@ fn do_send(ch chan int) {
fn test_channel_multi_buffered() { fn test_channel_multi_buffered() {
ch := chan int{cap: 100} ch := chan int{cap: 100}
resch := chan i64{} resch := chan i64{}
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_send(ch) spawn do_send(ch)
go do_send(ch) spawn do_send(ch)
go do_send(ch) spawn do_send(ch)
go do_send(ch) spawn do_send(ch)
mut sum := i64(0) mut sum := i64(0)
for _ in 0 .. 4 { for _ in 0 .. 4 {
sum += <-resch sum += <-resch

View file

@ -22,7 +22,7 @@ fn do_rec_calc_send(chs []chan mut St) {
fn test_channel_array_mut() { fn test_channel_array_mut() {
mut chs := [chan mut St{cap: 1}, chan mut St{}] mut chs := [chan mut St{cap: 1}, chan mut St{}]
go do_rec_calc_send(chs) spawn do_rec_calc_send(chs)
mut t := &St{ mut t := &St{
n: 100 n: 100
} }

View file

@ -23,11 +23,11 @@ fn do_send(ch chan int) {
fn test_channel_close_buffered_multi() { fn test_channel_close_buffered_multi() {
ch := chan int{cap: 10} ch := chan int{cap: 10}
resch := chan i64{} resch := chan i64{}
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_send(ch) spawn do_send(ch)
mut sum := i64(0) mut sum := i64(0)
for _ in 0 .. 4 { for _ in 0 .. 4 {
sum += <-resch sum += <-resch
@ -38,11 +38,11 @@ fn test_channel_close_buffered_multi() {
fn test_channel_close_unbuffered_multi() { fn test_channel_close_unbuffered_multi() {
ch := chan int{} ch := chan int{}
resch := chan i64{} resch := chan i64{}
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_send(ch) spawn do_send(ch)
mut sum := i64(0) mut sum := i64(0)
for _ in 0 .. 4 { for _ in 0 .. 4 {
sum += <-resch sum += <-resch
@ -53,8 +53,8 @@ fn test_channel_close_unbuffered_multi() {
fn test_channel_close_buffered() { fn test_channel_close_buffered() {
ch := chan int{cap: 100} ch := chan int{cap: 100}
resch := chan i64{} resch := chan i64{}
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_send(ch) spawn do_send(ch)
mut sum := i64(0) mut sum := i64(0)
sum += <-resch sum += <-resch
assert sum == i64(8000) * (8000 - 1) / 2 assert sum == i64(8000) * (8000 - 1) / 2
@ -63,8 +63,8 @@ fn test_channel_close_buffered() {
fn test_channel_close_unbuffered() { fn test_channel_close_unbuffered() {
ch := chan int{} ch := chan int{}
resch := chan i64{cap: 100} resch := chan i64{cap: 100}
go do_rec(ch, resch) spawn do_rec(ch, resch)
go do_send(ch) spawn do_send(ch)
mut sum := i64(0) mut sum := i64(0)
sum += <-resch sum += <-resch
assert sum == i64(8000) * (8000 - 1) / 2 assert sum == i64(8000) * (8000 - 1) / 2
@ -72,7 +72,7 @@ fn test_channel_close_unbuffered() {
fn test_channel_send_close_buffered() { fn test_channel_send_close_buffered() {
ch := chan int{cap: 1} ch := chan int{cap: 1}
t := go fn (ch chan int) { t := spawn fn (ch chan int) {
ch <- 31 ch <- 31
mut x := 45 mut x := 45
ch <- 17 or { x = -133 } ch <- 17 or { x = -133 }
@ -90,7 +90,7 @@ fn test_channel_send_close_buffered() {
fn test_channel_send_close_unbuffered() { fn test_channel_send_close_unbuffered() {
time.sleep(1 * time.second) time.sleep(1 * time.second)
ch := chan int{} ch := chan int{}
t := go fn (ch chan int) { t := spawn fn (ch chan int) {
mut x := 31 mut x := 31
ch <- 177 or { x = -71 } ch <- 177 or { x = -71 }

View file

@ -15,7 +15,7 @@ fn do_send(ch chan int, mut fin sync.Semaphore) {
fn test_channel_len_cap() { fn test_channel_len_cap() {
ch := chan int{cap: queue_len} ch := chan int{cap: queue_len}
mut sem := sync.new_semaphore() mut sem := sync.new_semaphore()
go do_send(ch, mut sem) spawn do_send(ch, mut sem)
sem.wait() sem.wait()
assert ch.cap == queue_len assert ch.cap == queue_len
assert ch.len == queue_fill assert ch.len == queue_fill

View file

@ -27,7 +27,7 @@ fn do_rec_calc_send(chs []chan i64, mut sem sync.Semaphore) {
fn test_channel_array_mut() { fn test_channel_array_mut() {
mut chs := [chan i64{}, chan i64{cap: 10}] mut chs := [chan i64{}, chan i64{cap: 10}]
mut sem := sync.new_semaphore() mut sem := sync.new_semaphore()
go do_rec_calc_send(chs, mut sem) spawn do_rec_calc_send(chs, mut sem)
mut t := i64(100) mut t := i64(100)
for _ in 0 .. num_iterations { for _ in 0 .. num_iterations {
chs[0] <- t chs[0] <- t

View file

@ -36,13 +36,13 @@ fn test_channel_polling() {
ch := chan int{cap: buflen} ch := chan int{cap: buflen}
resch := chan i64{} resch := chan i64{}
for _ in 0 .. nrec { for _ in 0 .. nrec {
go do_rec(ch, resch, objs_per_thread) spawn do_rec(ch, resch, objs_per_thread)
} }
mut n := nobj mut n := nobj
for _ in 0 .. nsend { for _ in 0 .. nsend {
end := n end := n
n -= objs_per_thread n -= objs_per_thread
go do_send(ch, n, end) spawn do_send(ch, n, end)
} }
mut sum := i64(0) mut sum := i64(0)
for _ in 0 .. nrec { for _ in 0 .. nrec {

View file

@ -11,7 +11,7 @@ fn f(ch chan int) {
fn test_push_or_unbuffered() { fn test_push_or_unbuffered() {
ch := chan int{} ch := chan int{}
go f(ch) spawn f(ch)
mut j := 0 mut j := 0
for { for {
ch <- j or { break } ch <- j or { break }
@ -23,7 +23,7 @@ fn test_push_or_unbuffered() {
fn test_push_or_buffered() { fn test_push_or_buffered() {
ch := chan int{cap: c} ch := chan int{cap: c}
go f(ch) spawn f(ch)
mut j := 0 mut j := 0
for { for {
ch <- j or { break } ch <- j or { break }
@ -50,9 +50,9 @@ fn g(ch chan int, res chan int) {
fn test_many_senders() { fn test_many_senders() {
ch := chan int{} ch := chan int{}
res := chan int{} res := chan int{}
go g(ch, res) spawn g(ch, res)
go g(ch, res) spawn g(ch, res)
go g(ch, res) spawn g(ch, res)
mut k := 0 mut k := 0
for _ in 0 .. 3 * n { for _ in 0 .. 3 * n {
k = <-ch k = <-ch

View file

@ -16,7 +16,7 @@ fn do_send(ch chan f64, val f64) ?f64 {
fn test_push_propargate() { fn test_push_propargate() {
ch := chan f64{} ch := chan f64{}
go f(ch) spawn f(ch)
mut s := 1.0 mut s := 1.0
for { for {
s = do_send(ch, s) or { break } s = do_send(ch, s) or { break }

View file

@ -31,10 +31,10 @@ fn test_select() {
chl := chan i64{cap: 1} chl := chan i64{cap: 1}
chb := chan u8{cap: 10} chb := chan u8{cap: 10}
recch := chan i64{cap: 0} recch := chan i64{cap: 0}
go do_rec_i64(recch) spawn do_rec_i64(recch)
go do_send_int(chi) spawn do_send_int(chi)
go do_send_u8(chb) spawn do_send_u8(chb)
go do_send_i64(chl) spawn do_send_i64(chl)
mut sum := i64(0) mut sum := i64(0)
mut rl := i64(0) mut rl := i64(0)
mut sl := i64(0) mut sl := i64(0)

View file

@ -79,7 +79,7 @@ fn test_select_blocks() {
} }
assert r == true assert r == true
assert t == true assert t == true
go f2(ch2, ch3, mut sem) spawn f2(ch2, ch3, mut sem)
n := <-ch3 n := <-ch3
assert n == 23 assert n == 23
ch2 <- St{ ch2 <- St{
@ -87,7 +87,7 @@ fn test_select_blocks() {
} }
sem.wait() sem.wait()
stopwatch := time.new_stopwatch() stopwatch := time.new_stopwatch()
go f1(ch1, ch2, ch3, ch4, ch5, mut sem) spawn f1(ch1, ch2, ch3, ch4, ch5, mut sem)
sem.wait() sem.wait()
elapsed_ms := f64(stopwatch.elapsed()) / time.millisecond elapsed_ms := f64(stopwatch.elapsed()) / time.millisecond
// https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/high-resolution-timers // https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/high-resolution-timers

View file

@ -16,8 +16,8 @@ fn test_select() {
chi := chan int{cap: 10} chi := chan int{cap: 10}
recch := chan i64{cap: 10} recch := chan i64{cap: 10}
chsum := chan i64{} chsum := chan i64{}
go do_rec_i64(recch, chsum) spawn do_rec_i64(recch, chsum)
go do_send_int(chi) spawn do_send_int(chi)
mut sum := i64(0) mut sum := i64(0)
mut sl := i64(0) mut sl := i64(0)
for _ in 0 .. 60000 + recch.cap { for _ in 0 .. 60000 + recch.cap {

View file

@ -28,12 +28,12 @@ fn test_select() {
chi := chan int{cap: 10} chi := chan int{cap: 10}
recch := chan i64{cap: 10} recch := chan i64{cap: 10}
chsum := chan i64{} chsum := chan i64{}
go do_rec_i64(recch, chsum) spawn do_rec_i64(recch, chsum)
go do_rec_i64(recch, chsum) spawn do_rec_i64(recch, chsum)
go do_rec_i64(recch, chsum) spawn do_rec_i64(recch, chsum)
go do_send_int(chi) spawn do_send_int(chi)
go do_send_int2(chi) spawn do_send_int2(chi)
go do_send_int3(chi) spawn do_send_int3(chi)
mut sum := i64(0) mut sum := i64(0)
mut sl := i64(0) mut sl := i64(0)
for _ in 0 .. 60000 + recch.cap { for _ in 0 .. 60000 + recch.cap {

View file

@ -51,15 +51,15 @@ fn test_select() {
chsum2 := chan i64{} chsum2 := chan i64{}
chsumf1 := chan f64{} chsumf1 := chan f64{}
chsumf2 := chan f64{} chsumf2 := chan f64{}
go do_send_int(ch1, 3) spawn do_send_int(ch1, 3)
go do_select(ch1, ch2, chf1, chf2, chsum1, chsum2) spawn do_select(ch1, ch2, chf1, chf2, chsum1, chsum2)
go do_rec_f64(chf1, chsumf1) spawn do_rec_f64(chf1, chsumf1)
go do_rec_f64(chf2, chsumf2) spawn do_rec_f64(chf2, chsumf2)
go do_rec_f64(chf2, chsumf2) spawn do_rec_f64(chf2, chsumf2)
go do_select(ch1, ch2, chf1, chf2, chsum1, chsum2) spawn do_select(ch1, ch2, chf1, chf2, chsum1, chsum2)
go do_send_int(ch2, 7) spawn do_send_int(ch2, 7)
go do_send_int(ch2, 17) spawn do_send_int(ch2, 17)
go do_select(ch1, ch2, chf1, chf2, chsum1, chsum2) spawn do_select(ch1, ch2, chf1, chf2, chsum1, chsum2)
sum1 := <-chsum1 + <-chsum1 + <-chsum1 sum1 := <-chsum1 + <-chsum1 + <-chsum1
sum2 := <-chsum2 + <-chsum2 + <-chsum2 sum2 := <-chsum2 + <-chsum2 + <-chsum2

View file

@ -53,10 +53,10 @@ fn test_select() {
mut chl := new_channel<i64>(1) mut chl := new_channel<i64>(1)
mut chb := new_channel<u8>(10) mut chb := new_channel<u8>(10)
mut recch := new_channel<i64>(0) mut recch := new_channel<i64>(0)
go do_rec_i64(mut recch) spawn do_rec_i64(mut recch)
go do_send_int(mut chi) spawn do_send_int(mut chi)
go do_send_u8(mut chb) spawn do_send_u8(mut chb)
go do_send_i64(mut chl) spawn do_send_i64(mut chl)
mut channels := [chi, recch, chl, chb] mut channels := [chi, recch, chl, chb]
directions := [Direction.pop, .push, .pop, .pop] directions := [Direction.pop, .push, .pop, .pop]
mut sum := i64(0) mut sum := i64(0)

View file

@ -24,7 +24,7 @@ fn test_many_times_once() {
// It is executed 10 times, but only once actually. // It is executed 10 times, but only once actually.
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
go run(mut m, mut co, c) spawn run(mut m, mut co, c)
} }
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
<-c <-c
@ -40,7 +40,7 @@ fn test_many_times_fifth() {
// It is executed 10 times, but only 5 times actually. // It is executed 10 times, but only 5 times actually.
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
go run(mut m, mut co, c) spawn run(mut m, mut co, c)
} }
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
<-c <-c

View file

@ -24,7 +24,7 @@ fn test_once() {
// It is executed 10 times, but only once actually. // It is executed 10 times, but only once actually.
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
go run(mut once, mut o, c) spawn run(mut once, mut o, c)
} }
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
<-c <-c

View file

@ -29,7 +29,7 @@ fn test_once() {
// It is executed 10 times, but only once actually. // It is executed 10 times, but only once actually.
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
go run(mut once, mut o, c) spawn run(mut once, mut o, c)
} }
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
<-c <-c

View file

@ -89,7 +89,7 @@ pub fn (mut pool PoolProcessor) work_on_pointers(items []voidptr) {
pool.waitgroup.add(njobs) pool.waitgroup.add(njobs)
for i := 0; i < njobs; i++ { for i := 0; i < njobs; i++ {
if njobs > 1 { if njobs > 1 {
go process_in_thread(mut pool, i) spawn process_in_thread(mut pool, i)
} else { } else {
// do not run concurrently, just use the same thread: // do not run concurrently, just use the same thread:
process_in_thread(mut pool, i) process_in_thread(mut pool, i)

View file

@ -44,10 +44,10 @@ fn test_select() {
mut chl := new_channel<i64>(1) mut chl := new_channel<i64>(1)
mut chb := new_channel<u8>(10) mut chb := new_channel<u8>(10)
mut recch := new_channel<i64>(0) mut recch := new_channel<i64>(0)
go do_rec_i64(mut recch) spawn do_rec_i64(mut recch)
go do_send_int(mut chi) spawn do_send_int(mut chi)
go do_send_u8(mut chb) spawn do_send_u8(mut chb)
go do_send_i64(mut chl) spawn do_send_i64(mut chl)
mut channels := [chi, recch, chl, chb] mut channels := [chi, recch, chl, chb]
directions := [Direction.pop, .push, .pop, .pop] directions := [Direction.pop, .push, .pop, .pop]
mut sum := i64(0) mut sum := i64(0)

View file

@ -15,7 +15,7 @@ fn test_count_10_times_1_cycle_should_result_10_cycles_with_sync() {
mut counter := &Counter{} mut counter := &Counter{}
wg.add(10) wg.add(10)
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
go count_one_cycle(mut counter, mut wg) spawn count_one_cycle(mut counter, mut wg)
} }
wg.wait() wg.wait()
assert counter.counter == u64(desired_iterations) assert counter.counter == u64(desired_iterations)
@ -29,7 +29,7 @@ fn test_count_10_times_1_cycle_should_not_be_10_cycles_without_sync() {
mut counter := &Counter{} mut counter := &Counter{}
wg.add(10) wg.add(10)
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
go count_one_cycle_without_sync(mut counter, mut wg) spawn count_one_cycle_without_sync(mut counter, mut wg)
} }
wg.wait() wg.wait()
// Note: we do not assert here, just print, because sometimes by chance counter.counter may be == desired_iterations // Note: we do not assert here, just print, because sometimes by chance counter.counter may be == desired_iterations

View file

@ -8,7 +8,7 @@ fn f(st Abc) {
fn test_chan_init() { fn test_chan_init() {
st := Abc{} st := Abc{}
go f(st) spawn f(st)
i := <-st.ch i := <-st.ch
assert i == 47 assert i == 47
} }

View file

@ -9,8 +9,8 @@ fn simple_thread() u64 {
fn test_sync_thread_id() { fn test_sync_thread_id() {
mtid := sync.thread_id() mtid := sync.thread_id()
eprintln('main thread_id: $sync.thread_id().hex()') eprintln('main thread_id: $sync.thread_id().hex()')
x := go simple_thread() x := spawn simple_thread()
y := go simple_thread() y := spawn simple_thread()
xtid := x.wait() xtid := x.wait()
ytid := y.wait() ytid := y.wait()
eprintln('main thread_id: $sync.thread_id().hex()') eprintln('main thread_id: $sync.thread_id().hex()')

View file

@ -10,7 +10,7 @@ fn test_waitgroup_reuse() {
wg.add(1) wg.add(1)
mut executed := false mut executed := false
go fn (mut wg WaitGroup, executed voidptr) { spawn fn (mut wg WaitGroup, executed voidptr) {
defer { defer {
wg.done() wg.done()
} }
@ -28,7 +28,7 @@ fn test_waitgroup_reuse() {
fn test_waitgroup_no_use() { fn test_waitgroup_no_use() {
mut done := false mut done := false
go fn (done voidptr) { spawn fn (done voidptr) {
time.sleep(1 * time.second) time.sleep(1 * time.second)
if *(&bool(done)) == false { if *(&bool(done)) == false {
panic('test_waitgroup_no_use did not complete in time') panic('test_waitgroup_no_use did not complete in time')

View file

@ -252,7 +252,7 @@ fn (mut tasks Tasks) run() {
} }
work.close() work.close()
for _ in 0 .. vjobs { for _ in 0 .. vjobs {
go work_processor(work, results) spawn work_processor(work, results)
} }
if github_job == '' { if github_job == '' {
println('') println('')

View file

@ -1170,7 +1170,7 @@ pub fn (mut f Fmt) global_decl(node ast.GlobalDecl) {
} }
pub fn (mut f Fmt) go_expr(node ast.GoExpr) { pub fn (mut f Fmt) go_expr(node ast.GoExpr) {
f.write('go ') f.write('spawn ')
f.call_expr(node.call_expr) f.call_expr(node.call_expr)
} }

View file

@ -90,7 +90,7 @@ fn main() {
for m, n in ma { for m, n in ma {
iss := m iss := m
} }
go async(0, 'hello') spawn async(0, 'hello')
fn_in_var := fn (number int) { fn_in_var := fn (number int) {
println('number: $number') println('number: $number')
} }

View file

@ -45,7 +45,7 @@ pub fn start_reloader(mut r live.LiveReloadInfo) {
eprintln(err) eprintln(err)
exit(1) exit(1)
} }
go reloader(mut r) spawn reloader(mut r)
} }
fn elog(r &live.LiveReloadInfo, s string) { fn elog(r &live.LiveReloadInfo, s string) {

View file

@ -3,7 +3,7 @@ import sync
fn test_go_anon_fn() { fn test_go_anon_fn() {
mut wg := sync.new_waitgroup() mut wg := sync.new_waitgroup()
wg.add(1) wg.add(1)
go fn (mut wg sync.WaitGroup) { spawn fn (mut wg sync.WaitGroup) {
wg.done() wg.done()
}(mut wg) }(mut wg)
wg.wait() wg.wait()

View file

@ -35,8 +35,8 @@ fn test_array_map_ref() {
a_ref[1] = 17 a_ref[1] = 17
} }
assert a_ref.len == 5 assert a_ref.len == 5
t1 := go mod_map(shared m_shared) t1 := spawn mod_map(shared m_shared)
t2 := go mod_array(shared a_shared) t2 := spawn mod_array(shared a_shared)
lock m_shared, a_shared { lock m_shared, a_shared {
a_shared[4] = -12.25 a_shared[4] = -12.25
m_shared['tz'] = 73.75 m_shared['tz'] = 73.75

View file

@ -26,7 +26,7 @@ fn test_array_of_threads_wait() {
println('Async') println('Async')
mut results := []thread f64{len: 16, cap: 16} mut results := []thread f64{len: 16, cap: 16}
for num in 0 .. 15 { for num in 0 .. 15 {
results << go async(size, init_val + num) results << spawn async(size, init_val + num)
} }
waited_results := results.wait() waited_results := results.wait()

View file

@ -11,7 +11,7 @@ mut:
fn test_atomic() { fn test_atomic() {
mut app := &App{} mut app := &App{}
for i in 0 .. 10 { for i in 0 .. 10 {
go app.run() spawn app.run()
} }
time.sleep(200 * time.millisecond) time.sleep(200 * time.millisecond)
println('idx=$app.idx') println('idx=$app.idx')

View file

@ -13,8 +13,8 @@ fn add_elements(shared foo []int, n int) {
fn test_autolocked_array() { fn test_autolocked_array() {
shared abc := &[0] shared abc := &[0]
go add_elements(shared abc, 1) spawn add_elements(shared abc, 1)
go add_elements(shared abc, 3) spawn add_elements(shared abc, 3)
for _ in 0 .. iterations_per_thread { for _ in 0 .. iterations_per_thread {
abc << 0 abc << 0
} }

View file

@ -14,8 +14,8 @@ fn inc_elements(shared foo []int, n int, mut sem sync.Semaphore) {
fn test_autolocked_array_2() { fn test_autolocked_array_2() {
shared abc := &[0, 0, 0] shared abc := &[0, 0, 0]
mut sem := sync.new_semaphore() mut sem := sync.new_semaphore()
go inc_elements(shared abc, 1, mut sem) spawn inc_elements(shared abc, 1, mut sem)
go inc_elements(shared abc, 2, mut sem) spawn inc_elements(shared abc, 2, mut sem)
for _ in 0 .. iterations_per_thread2 { for _ in 0 .. iterations_per_thread2 {
unsafe { unsafe {
abc[2]++ abc[2]++

View file

@ -54,7 +54,7 @@ fn main() {
eprintln('usage:\n\t${os.args[0]} [num_iterations]') eprintln('usage:\n\t${os.args[0]} [num_iterations]')
exit(1) exit(1)
} }
go waste_mem() spawn waste_mem()
mut last := time.sys_mono_now() mut last := time.sys_mono_now()
for _ in 0 .. n_iterations { for _ in 0 .. n_iterations {
now := time.sys_mono_now() now := time.sys_mono_now()

View file

@ -13,8 +13,8 @@ const (
fn test_return_lock() { fn test_return_lock() {
start := time.now() start := time.now()
shared s := AA{'3'} shared s := AA{'3'}
go printer(shared s, start) spawn printer(shared s, start)
go fn (shared s AA, start time.Time) { spawn fn (shared s AA, start time.Time) {
for { for {
reader(shared s) reader(shared s)
if time.now() - start > run_time { if time.now() - start > run_time {

View file

@ -18,7 +18,7 @@ fn test_printing_of_channels() {
val: 1000 val: 1000
another: fch another: fch
} }
res := (go fn1(ch)).wait() res := (spawn fn1(ch)).wait()
println(res) println(res)
println(ch) println(ch)
assert res.str().contains('another: chan f64{cap: 100, closed: 0}') assert res.str().contains('another: chan f64{cap: 100, closed: 0}')
@ -40,7 +40,7 @@ fn func(ch chan As) {
fn test_chan_of_sumtype() { fn test_chan_of_sumtype() {
a := chan As{} a := chan As{}
go func(a) spawn func(a)
ret := <-a ret := <-a
println(ret) println(ret)
assert '$ret' == 'As(Aa{})' assert '$ret' == 'As(Aa{})'

View file

@ -16,7 +16,7 @@ fn test_comptime_if_expr_of_threads() {
println('Async') println('Async')
mut results := []thread f64{cap: 16} mut results := []thread f64{cap: 16}
for num in 0 .. 15 { for num in 0 .. 15 {
results << go async(size, num) results << spawn async(size, num)
} }
waited_results := results.wait() waited_results := results.wait()

View file

@ -1,5 +1,5 @@
fn abc() { fn abc() {
go fn () {}() spawn fn () {}()
} }
fn test_if_threads() { fn test_if_threads() {

View file

@ -20,7 +20,7 @@ fn test_default_stack_depth() {
// and would have failed on macos, where the default thread size // and would have failed on macos, where the default thread size
// is just 512KB, if V was not changed to have a default for // is just 512KB, if V was not changed to have a default for
// `-thread-stack-size` of 8MB. // `-thread-stack-size` of 8MB.
t := go abc(10) t := spawn abc(10)
res := t.wait() res := t.wait()
assert res == 55 assert res == 55
} }

View file

@ -71,7 +71,7 @@ fn test_defer_with_anon_fn() {
assert f.add(1) == 111 assert f.add(1) == 111
} }
go fn () { spawn fn () {
defer { defer {
println('deferred 1') println('deferred 1')
} }

View file

@ -2,7 +2,7 @@ module main
fn test_fixed_array_of_threads() { fn test_fixed_array_of_threads() {
mut avar := [8]thread string{} mut avar := [8]thread string{}
avar[0] = go printme() avar[0] = spawn printme()
ret := avar[0].wait() ret := avar[0].wait()
assert ret == 'me' assert ret == 'me'
} }

View file

@ -27,7 +27,7 @@ fn test_for_match() {
fn test_for_select() { fn test_for_select() {
ch1 := chan int{} ch1 := chan int{}
ch2 := chan f64{} ch2 := chan f64{}
go do_send(ch1, ch2) spawn do_send(ch1, ch2)
mut a := 0 mut a := 0
mut b := 0 mut b := 0
for select { for select {

View file

@ -6,7 +6,7 @@ fn test_go_anon_fn_call_with_ref_arg() {
foo := &Foo{ foo := &Foo{
bar: 'hello' bar: 'hello'
} }
g := go fn (foo Foo) string { g := spawn fn (foo Foo) string {
return foo.bar return foo.bar
}(foo) }(foo)
ret := g.wait() ret := g.wait()

View file

@ -7,7 +7,7 @@ fn sum1(a int, b int) int {
} }
sum_func2 := sum_func1 sum_func2 := sum_func1
g := go sum_func2(a, b) g := spawn sum_func2(a, b)
result := g.wait() result := g.wait()
return result return result
@ -21,7 +21,7 @@ fn sum2(a int, b int) int {
sum_func1 := add sum_func1 := add
sum_func2 := sum_func1 sum_func2 := sum_func1
g := go sum_func2(a, b) g := spawn sum_func2(a, b)
result := g.wait() result := g.wait()
return result return result

View file

@ -9,7 +9,7 @@ fn f(x f64) f64 {
fn test_array_thread_f64_wait() { fn test_array_thread_f64_wait() {
mut r := []thread f64{cap: 10} mut r := []thread f64{cap: 10}
for i in 0 .. 10 { for i in 0 .. 10 {
r << go f(f64(i) + 0.5) r << spawn f(f64(i) + 0.5)
} }
x := r.wait() x := r.wait()
assert x == [0.25, 2.25, 6.25, 12.25, 20.25, 30.25, 42.25, 56.25, 72.25, 90.25] assert x == [0.25, 2.25, 6.25, 12.25, 20.25, 30.25, 42.25, 56.25, 72.25, 90.25]
@ -24,13 +24,13 @@ fn g(shared a []int, i int) {
fn test_array_thread_void_wait() { fn test_array_thread_void_wait() {
shared a := [2, 3, 5, 7, 11, 13, 17] shared a := [2, 3, 5, 7, 11, 13, 17]
t := [ t := [
go g(shared a, 0), spawn g(shared a, 0),
go g(shared a, 3), spawn g(shared a, 3),
go g(shared a, 6), spawn g(shared a, 6),
go g(shared a, 2), spawn g(shared a, 2),
go g(shared a, 1), spawn g(shared a, 1),
go g(shared a, 5), spawn g(shared a, 5),
go g(shared a, 4), spawn g(shared a, 4),
] ]
println('threads started') println('threads started')
t.wait() t.wait()
@ -43,9 +43,9 @@ fn test_void_thread_decl() {
shared a := [2, 3, 9] shared a := [2, 3, 9]
mut t1 := thread(0) mut t1 := thread(0)
mut tarr := []thread{len: 2} mut tarr := []thread{len: 2}
t1 = go g(shared a, 0) t1 = spawn g(shared a, 0)
tarr[0] = go g(shared a, 1) tarr[0] = spawn g(shared a, 1)
tarr[1] = go g(shared a, 2) tarr[1] = spawn g(shared a, 2)
t1.wait() t1.wait()
tarr.wait() tarr.wait()
rlock a { rlock a {

View file

@ -6,7 +6,7 @@ fn test_go_call_anon_fn_with_closure1() {
return a return a
} }
g := go b() g := spawn b()
ret := g.wait() ret := g.wait()
assert ret == 1 assert ret == 1
} }
@ -17,7 +17,7 @@ fn test_go_call_anon_fn_with_closure2() {
'key2': 2 'key2': 2
} }
h := go fn [m] () int { h := spawn fn [m] () int {
println(m['key2']) println(m['key2'])
return m['key2'] return m['key2']
}() }()

View file

@ -1,7 +1,7 @@
const text = 'Hello world' const text = 'Hello world'
fn test_go_call_fn_return() { fn test_go_call_fn_return() {
hex_go := go text.bytes().hex() hex_go := spawn text.bytes().hex()
hex := text.bytes().hex() hex := text.bytes().hex()
assert hex == '48656c6c6f20776f726c64' assert hex == '48656c6c6f20776f726c64'

View file

@ -8,7 +8,7 @@ fn test_go_call_fn_using_map_value() {
mut fns := map[string]fn (int, int) int{} mut fns := map[string]fn (int, int) int{}
fns['sum'] = sum fns['sum'] = sum
g := go fns['sum'](2, 3) g := spawn fns['sum'](2, 3)
x := g.wait() x := g.wait()
println('$x') println('$x')

View file

@ -8,7 +8,7 @@ fn on_connect() {
} }
fn test_go_call_fn_with_anon_fn_arg() { fn test_go_call_fn_with_anon_fn_arg() {
g := go start(on_connect) g := spawn start(on_connect)
ret := g.wait() ret := g.wait()
assert ret == 'ok!!' assert ret == 'ok!!'
} }

View file

@ -7,7 +7,7 @@ fn test<T>(c chan int, s T) {
fn test_go_generic_fn() { fn test_go_generic_fn() {
mut c := chan int{} mut c := chan int{}
go test<string>(c, 'abcd') spawn test<string>(c, 'abcd')
x := <-c x := <-c
assert x == 123 assert x == 123
println('bye') println('bye')

View file

@ -21,7 +21,7 @@ fn test_go_call_interface_method() {
tasks << Task2{} tasks << Task2{}
for task in tasks { for task in tasks {
go task.task() spawn task.task()
} }
assert true assert true

View file

@ -3,7 +3,7 @@ fn create_random_frames(amount int, pixels int) [][][]int {
} }
fn test_go_can_be_used_with_functions_returning_arrays() { fn test_go_can_be_used_with_functions_returning_arrays() {
x := go create_random_frames(2, 2) x := spawn create_random_frames(2, 2)
res := x.wait() res := x.wait()
assert res == [[[2, 2]]] assert res == [[[2, 2]]]
} }

View file

@ -3,7 +3,7 @@ fn f(x int, y f64) f64 {
} }
fn test_go_return() { fn test_go_return() {
r := go f(3, 4.0) r := spawn f(3, 4.0)
z := r.wait() z := r.wait()
assert typeof(z).name == 'f64' assert typeof(z).name == 'f64'
assert z == 12.0 assert z == 12.0

View file

@ -15,7 +15,7 @@ fn f(x int, y f64, shared s St) {
fn test_go_return() { fn test_go_return() {
shared t := &St{} shared t := &St{}
r := go f(3, 4.0, shared t) r := spawn f(3, 4.0, shared t)
r.wait() r.wait()
rlock t { rlock t {
assert t.x == 12.0 assert t.x == 12.0

View file

@ -12,7 +12,7 @@ fn test_method_go_wait() {
test: 'hi' test: 'hi'
} }
} }
thread := go a.sub.get() thread := spawn a.sub.get()
r := thread.wait() r := thread.wait()
assert r == 'hi' assert r == 'hi'
} }

View file

@ -17,8 +17,8 @@ fn g(n int) ? {
} }
fn test_opt_val_wait() { fn test_opt_val_wait() {
h1 := go f(-1) h1 := spawn f(-1)
h2 := go f(3) h2 := spawn f(3)
r1 := h1.wait() or { 17.0 } r1 := h1.wait() or { 17.0 }
r2 := h2.wait() or { 23.0 } r2 := h2.wait() or { 23.0 }
assert r1 == 17.0 assert r1 == 17.0
@ -26,8 +26,8 @@ fn test_opt_val_wait() {
} }
fn test_opt_void_wait() { fn test_opt_void_wait() {
h1 := go g(2) h1 := spawn g(2)
h2 := go g(3) h2 := spawn g(3)
mut x := 0 mut x := 0
mut y := 0 mut y := 0
h1.wait() or { x = 1 } h1.wait() or { x = 1 }
@ -37,8 +37,8 @@ fn test_opt_void_wait() {
} }
fn propagate(n int, m int) ?f64 { fn propagate(n int, m int) ?f64 {
h1 := go f(n) h1 := spawn f(n)
h2 := go g(m) h2 := spawn g(m)
r := h1.wait()? r := h1.wait()?
h2.wait()? h2.wait()?
return r return r
@ -56,7 +56,7 @@ fn test_propagate() {
fn test_array_void_interate() { fn test_array_void_interate() {
mut r := []thread ?{} mut r := []thread ?{}
for i in 0 .. 3 { for i in 0 .. 3 {
r << go g(i) r << spawn g(i)
} }
mut res := []int{len: 3, init: 17} mut res := []int{len: 3, init: 17}
for i, t in r { for i, t in r {
@ -70,7 +70,7 @@ fn test_array_void_interate() {
fn test_array_val_interate() { fn test_array_val_interate() {
mut r := []thread ?f64{} mut r := []thread ?f64{}
for i in -1 .. 2 { for i in -1 .. 2 {
r << go f(i) r << spawn f(i)
} }
mut res := []f64{len: 3} mut res := []f64{len: 3}
for i, t in r { for i, t in r {
@ -94,15 +94,15 @@ fn get_only_a_result_return() ! {
} }
fn test_only_a_option_return() { fn test_only_a_option_return() {
t1 := go get_only_a_option_return(true) t1 := spawn get_only_a_option_return(true)
t1.wait() or { assert false } t1.wait() or { assert false }
t2 := go get_only_a_option_return(false) t2 := spawn get_only_a_option_return(false)
t2.wait() or { assert true } t2.wait() or { assert true }
assert true assert true
} }
fn test_only_a_result_return() { fn test_only_a_result_return() {
t := go get_only_a_result_return() t := spawn get_only_a_result_return()
t.wait() or { assert true } t.wait() or { assert true }
assert true assert true
} }

Some files were not shown because too many files have changed in this diff Show more