mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: replace go
with spawn
This commit is contained in:
parent
a082328e40
commit
e81e0ac708
@ -298,7 +298,7 @@ pub fn (mut ts TestSession) test() {
|
||||
ts.nmessages = chan LogMessage{cap: 10000}
|
||||
ts.nprint_ended = chan int{cap: 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.work_on_pointers(unsafe { remaining_files.pointers() })
|
||||
ts.benchmark.stop()
|
||||
|
@ -73,7 +73,7 @@ fn main() {
|
||||
if ctx.is_verbose {
|
||||
eprintln('> args: $args | context: $ctx')
|
||||
}
|
||||
go do_timeout(&ctx)
|
||||
spawn do_timeout(&ctx)
|
||||
for i := 1; true; i++ {
|
||||
ctx.println('$i')
|
||||
time.sleep(ctx.period_ms * time.millisecond)
|
||||
|
@ -210,7 +210,7 @@ fn (vd VDoc) render_parallel(out Output) {
|
||||
work.close()
|
||||
wg.add(vjobs)
|
||||
for _ in 0 .. vjobs {
|
||||
go vd.work_processor(mut work, mut wg)
|
||||
spawn vd.work_processor(mut work, mut wg)
|
||||
}
|
||||
wg.wait()
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ fn main() {
|
||||
mut source := os.read_file(context.path)!
|
||||
source = source[..context.cut_index]
|
||||
|
||||
go fn (ms int) {
|
||||
spawn fn (ms int) {
|
||||
time.sleep(ms * time.millisecond)
|
||||
exit(ecode_timeout)
|
||||
}(context.timeout_ms)
|
||||
@ -248,7 +248,7 @@ fn (mut context Context) start_printing() {
|
||||
if !context.is_linear && !context.is_silent {
|
||||
println('\n')
|
||||
}
|
||||
go context.print_periodic_status()
|
||||
spawn context.print_periodic_status()
|
||||
}
|
||||
|
||||
fn (mut context Context) stop_printing() {
|
||||
|
@ -381,6 +381,6 @@ fn (mut context Context) worker_main() {
|
||||
context.is_exiting = true
|
||||
context.kill_pgroup()
|
||||
}) or { panic(err) }
|
||||
go context.compilation_runner_loop()
|
||||
spawn context.compilation_runner_loop()
|
||||
change_detection_loop(context)
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ fn expensive_computing(id int, duration int) {
|
||||
|
||||
fn main() {
|
||||
mut threads := []thread{}
|
||||
threads << go expensive_computing(1, 100)
|
||||
threads << go expensive_computing(2, 500)
|
||||
threads << go expensive_computing(3, 1000)
|
||||
threads << spawn expensive_computing(1, 100)
|
||||
threads << spawn expensive_computing(2, 500)
|
||||
threads << spawn expensive_computing(3, 1000)
|
||||
// Join all tasks
|
||||
threads.wait()
|
||||
println('All jobs finished!')
|
||||
|
@ -26,7 +26,7 @@ fn main() {
|
||||
mut wg := sync.new_waitgroup()
|
||||
wg.add(2)
|
||||
// Run tasks async
|
||||
go vlang_time(mut wg)
|
||||
go remote_ip(mut wg)
|
||||
spawn vlang_time(mut wg)
|
||||
spawn remote_ip(mut wg)
|
||||
wg.wait()
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ fn expensive_computing(i int) int {
|
||||
fn main() {
|
||||
mut threads := []thread int{}
|
||||
for i in 1 .. 10 {
|
||||
threads << go expensive_computing(i)
|
||||
threads << spawn expensive_computing(i)
|
||||
}
|
||||
// Join all tasks
|
||||
r := threads.wait()
|
||||
|
@ -198,7 +198,7 @@ fn main() {
|
||||
network: [2, 2, 1]
|
||||
}
|
||||
app.start()
|
||||
go app.run()
|
||||
spawn app.run()
|
||||
app.gg.run()
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ fn (mut state AppState) update() {
|
||||
threads.wait()
|
||||
}
|
||||
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{}
|
||||
@ -237,6 +237,6 @@ fn main() {
|
||||
scroll_fn: graphics_scroll
|
||||
user_data: state
|
||||
)
|
||||
go state.update()
|
||||
spawn state.update()
|
||||
state.gg.run()
|
||||
}
|
||||
|
@ -58,6 +58,6 @@ fn main() {
|
||||
frame_fn: graphics_frame
|
||||
user_data: state
|
||||
)
|
||||
go state.update()
|
||||
spawn state.update()
|
||||
state.gg.run()
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ fn main() {
|
||||
|
||||
fn init(mut app App) {
|
||||
// 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.
|
||||
|
@ -45,7 +45,7 @@ fn main() {
|
||||
)
|
||||
// window.onkeydown(key_down)
|
||||
println('Starting the game loop...')
|
||||
go game.run()
|
||||
spawn game.run()
|
||||
game.gg.run()
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ fn main() {
|
||||
mut wg := sync.new_waitgroup()
|
||||
for i := 0; i < 50; i++ {
|
||||
wg.add(1)
|
||||
go send_request(mut wg)
|
||||
spawn send_request(mut wg)
|
||||
}
|
||||
wg.wait()
|
||||
}
|
||||
|
@ -24,14 +24,14 @@ fn main() {
|
||||
}
|
||||
|
||||
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) ! {
|
||||
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))
|
||||
}
|
||||
|
@ -38,16 +38,16 @@ fn main() {
|
||||
|
||||
// start a worker on each core
|
||||
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) ! {
|
||||
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,
|
||||
grid: app.args.grid
|
||||
|
@ -48,7 +48,7 @@ pub fn new_app(args simargs.ParallelArgs) &App {
|
||||
fn init(mut app App) {
|
||||
app.iidx = app.gg.new_streaming_image(app.args.grid.width, app.args.grid.height, 4,
|
||||
pixel_format: .rgba8)
|
||||
go pixels_worker(mut app)
|
||||
spawn pixels_worker(mut app)
|
||||
}
|
||||
|
||||
fn frame(mut app App) {
|
||||
|
@ -35,7 +35,7 @@ fn main() {
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -34,10 +34,10 @@ fn main() {
|
||||
}
|
||||
|
||||
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) ! {
|
||||
request_chan <- request
|
||||
|
@ -129,7 +129,7 @@ fn main() {
|
||||
)
|
||||
app.qt = app.qt.create(0, 0, 1340, 640, 8, 4, 0)
|
||||
app.start()
|
||||
go app.run()
|
||||
spawn app.run()
|
||||
app.gg.run()
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ fn main() {
|
||||
eprintln('Listen on $laddr ...')
|
||||
for {
|
||||
mut socket := server.accept()!
|
||||
go handle_client(mut socket)
|
||||
spawn handle_client(mut socket)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,6 @@ 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')) }
|
||||
spawn ws.listen() // or { println(term.red('error on listen $err')) }
|
||||
return ws
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import time
|
||||
import net.websocket
|
||||
|
||||
fn main() {
|
||||
go start_server()
|
||||
spawn start_server()
|
||||
time.sleep(100 * time.millisecond)
|
||||
start_client()!
|
||||
}
|
||||
@ -65,7 +65,7 @@ fn start_client() ! {
|
||||
// // println('type: $msg.opcode payload:\n$msg.payload ref: $r')
|
||||
// }, &r)
|
||||
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') }
|
||||
unsafe {
|
||||
ws.free()
|
||||
|
@ -195,7 +195,7 @@ fn new_x11_clipboard(selection AtomType) &Clipboard {
|
||||
cb.selection = cb.get_atom(selection)
|
||||
// start the listener on another thread or
|
||||
// we will be locked and will have to hard exit
|
||||
go cb.start_listener()
|
||||
spawn cb.start_listener()
|
||||
return cb
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ fn propagate_cancel(mut parent Context, mut child Canceler) {
|
||||
}
|
||||
}
|
||||
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()
|
||||
select {
|
||||
_ := <-pdone {
|
||||
|
@ -13,7 +13,7 @@ fn test_with_cancel() {
|
||||
// the internal routine started by gen.
|
||||
gen := fn (mut ctx context.Context) 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
|
||||
ch := ctx.done()
|
||||
for {
|
||||
|
@ -51,7 +51,7 @@ pub fn with_deadline(mut parent Context, d time.Time) (Context, CancelFn) {
|
||||
}
|
||||
|
||||
if ctx.err() is none {
|
||||
go fn (mut ctx TimerContext, dur time.Duration) {
|
||||
spawn fn (mut ctx TimerContext, dur time.Duration) {
|
||||
time.sleep(dur)
|
||||
ctx.cancel(true, deadline_exceeded)
|
||||
}(mut ctx, dur)
|
||||
|
@ -30,7 +30,7 @@ pub fn merge(ctx context.Context, ctxs ...context.Context) (context.Context, con
|
||||
cancel_fn: cancel
|
||||
cancel_ctx: cancel_ctx
|
||||
}
|
||||
go octx.run()
|
||||
spawn octx.run()
|
||||
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) {
|
||||
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()
|
||||
c1done := ctx1.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) {
|
||||
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()
|
||||
cdone := ctx.done()
|
||||
select {
|
||||
|
@ -63,7 +63,7 @@ fn test_log_mutable_reference() {
|
||||
println(@FN + ' start')
|
||||
mut log := new_log()
|
||||
assert typeof(log).name == '&log.Log'
|
||||
go log_mutable_statements(mut log)
|
||||
spawn log_mutable_statements(mut log)
|
||||
delay() // wait to finish
|
||||
assert true
|
||||
println(@FN + ' end')
|
||||
@ -75,7 +75,7 @@ fn test_logger_mutable_reference() {
|
||||
mut logger := new_log_as_logger()
|
||||
logger.set_level(.warn)
|
||||
assert typeof(logger).name == '&log.Logger'
|
||||
go logger_mutable_statements(mut logger)
|
||||
spawn logger_mutable_statements(mut logger)
|
||||
delay() // wait to finish
|
||||
assert true
|
||||
println(@FN + ' end')
|
||||
|
@ -5,7 +5,7 @@ fn test_server_stop() {
|
||||
mut server := &http.Server{
|
||||
accept_timeout: 1 * time.second
|
||||
}
|
||||
t := go server.listen_and_serve()
|
||||
t := spawn server.listen_and_serve()
|
||||
time.sleep(250 * time.millisecond)
|
||||
mut watch := time.new_stopwatch()
|
||||
server.stop()
|
||||
@ -20,7 +20,7 @@ fn test_server_close() {
|
||||
accept_timeout: 1 * time.second
|
||||
handler: MyHttpHandler{}
|
||||
}
|
||||
t := go server.listen_and_serve()
|
||||
t := spawn server.listen_and_serve()
|
||||
time.sleep(250 * time.millisecond)
|
||||
mut watch := time.new_stopwatch()
|
||||
server.close()
|
||||
@ -67,7 +67,7 @@ fn test_server_custom_handler() {
|
||||
handler: handler
|
||||
port: cport
|
||||
}
|
||||
t := go server.listen_and_serve()
|
||||
t := spawn server.listen_and_serve()
|
||||
for server.status() != .running {
|
||||
time.sleep(10 * time.millisecond)
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ fn start_server(schannel chan int, shared ctx Context) {
|
||||
}
|
||||
continue
|
||||
}
|
||||
go receive_data(mut tcp_con, shared ctx)
|
||||
spawn receive_data(mut tcp_con, shared ctx)
|
||||
lock ctx {
|
||||
ctx.ok_server_accepts++
|
||||
}
|
||||
@ -109,11 +109,11 @@ fn test_tcp_self_dialing() {
|
||||
start_time := time.now()
|
||||
shared ctx := &Context{}
|
||||
mut server_channel := chan int{cap: 1}
|
||||
go start_server(server_channel, shared ctx)
|
||||
spawn start_server(server_channel, shared ctx)
|
||||
svalue := <-server_channel
|
||||
elog('>>> server was started: ${svalue}. Starting clients:')
|
||||
for i := int(0); i < 20; i++ {
|
||||
go start_client(i, shared ctx)
|
||||
spawn start_client(i, shared ctx)
|
||||
elog('>>> started client $i')
|
||||
// time.sleep(2 * time.millisecond)
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ fn setup() (&net.TcpListener, &net.TcpConn, &net.TcpConn) {
|
||||
mut server := net.listen_tcp(.ip6, server_port) or { panic(err) }
|
||||
|
||||
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) }
|
||||
|
||||
socket := <-c
|
||||
|
@ -64,7 +64,7 @@ fn test_tcp_ip6() {
|
||||
|
||||
fn start_echo_server(mut l net.TcpListener) {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ fn echo() ! {
|
||||
fn test_udp() {
|
||||
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') }
|
||||
|
||||
l.close() or {}
|
||||
|
@ -30,7 +30,7 @@ fn handle_conn(mut c unix.StreamConn) {
|
||||
fn echo_server(mut l unix.StreamListener) ! {
|
||||
for {
|
||||
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() {
|
||||
assert os.exists(test_port) == false
|
||||
mut l := unix.listen_stream(test_port) or { panic(err) }
|
||||
go echo_server(mut l)
|
||||
spawn echo_server(mut l)
|
||||
echo() or { panic(err) }
|
||||
l.close() or {}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ fn testsuite_end() {
|
||||
|
||||
fn test_that_net_and_net_unix_can_be_imported_together_without_conflicts() {
|
||||
mut l := unix.listen_stream(test_port) or { panic(err) }
|
||||
go echo_server(mut l)
|
||||
spawn echo_server(mut l)
|
||||
defer {
|
||||
l.close() or {}
|
||||
}
|
||||
|
@ -64,10 +64,10 @@ pub fn (mut s Server) listen() ! {
|
||||
s.logger.info('websocket server: start listen on port $s.port')
|
||||
s.ls = net.listen_tcp(s.family, ':$s.port')!
|
||||
s.set_state(.open)
|
||||
go s.handle_ping()
|
||||
spawn s.handle_ping()
|
||||
for {
|
||||
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')
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ fn test_ws_ipv6() {
|
||||
}
|
||||
port := 30000 + rand.intn(1024) or { 0 }
|
||||
eprintln('> port ipv6: $port')
|
||||
go start_server(.ip6, port)
|
||||
spawn start_server(.ip6, port)
|
||||
time.sleep(1500 * time.millisecond)
|
||||
ws_test(.ip6, 'ws://localhost:$port') or {
|
||||
eprintln('> error while connecting .ip6, err: $err')
|
||||
@ -42,7 +42,7 @@ fn test_ws_ipv4() {
|
||||
}
|
||||
port := 30000 + rand.intn(1024) or { 0 }
|
||||
eprintln('> port ipv4: $port')
|
||||
go start_server(.ip, port)
|
||||
spawn start_server(.ip, port)
|
||||
time.sleep(1500 * time.millisecond)
|
||||
ws_test(.ip, 'ws://localhost:$port') or {
|
||||
eprintln('> error while connecting .ip, err: $err')
|
||||
@ -113,7 +113,7 @@ fn ws_test(family net.AddrFamily, uri string) ! {
|
||||
}
|
||||
}, test_results)
|
||||
ws.connect() or { panic('fail to connect, err: $err') }
|
||||
go ws.listen()
|
||||
spawn ws.listen()
|
||||
text := ['a'].repeat(2)
|
||||
for msg in text {
|
||||
ws.write(msg.bytes(), .text_frame) or { panic('fail to write to websocket, err: $err') }
|
||||
|
@ -240,7 +240,7 @@ pub fn new(config Config) &Picoev {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ fn main() {
|
||||
mut no := nobj
|
||||
for i in 0 .. nrec {
|
||||
n := no / (nrec - i)
|
||||
go do_rec(ch, resch, n)
|
||||
spawn do_rec(ch, resch, n)
|
||||
no -= n
|
||||
}
|
||||
$if debug {
|
||||
@ -49,7 +49,7 @@ fn main() {
|
||||
n := no / (nsend - i)
|
||||
end := no
|
||||
no -= n
|
||||
go do_send(ch, no, end)
|
||||
spawn do_send(ch, no, end)
|
||||
}
|
||||
assert no == 0
|
||||
mut sum := i64(0)
|
||||
|
@ -117,11 +117,11 @@ fn main() {
|
||||
}
|
||||
ctx.pops_wg.add(n_readers)
|
||||
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)
|
||||
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()
|
||||
eprintln('>> all pushes done')
|
||||
|
@ -10,7 +10,7 @@ fn do_send(ch chan int) {
|
||||
|
||||
fn test_channel_buffered() {
|
||||
ch := chan int{cap: 1000}
|
||||
go do_send(ch)
|
||||
spawn do_send(ch)
|
||||
mut sum := i64(0)
|
||||
for _ in 0 .. num_iterations {
|
||||
sum += <-ch
|
||||
|
@ -10,7 +10,7 @@ fn do_send(ch chan int) {
|
||||
|
||||
fn test_channel_unbuffered() {
|
||||
ch := chan int{}
|
||||
go do_send(ch)
|
||||
spawn do_send(ch)
|
||||
mut sum := i64(0)
|
||||
for _ in 0 .. num_iterations {
|
||||
sum += <-ch
|
||||
|
@ -16,14 +16,14 @@ fn do_send(ch chan int) {
|
||||
fn test_channel_multi_unbuffered() {
|
||||
ch := chan int{}
|
||||
resch := chan i64{}
|
||||
go do_rec(ch, resch)
|
||||
go do_rec(ch, resch)
|
||||
go do_rec(ch, resch)
|
||||
go do_rec(ch, resch)
|
||||
go do_send(ch)
|
||||
go do_send(ch)
|
||||
go do_send(ch)
|
||||
go do_send(ch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_send(ch)
|
||||
spawn do_send(ch)
|
||||
spawn do_send(ch)
|
||||
spawn do_send(ch)
|
||||
mut sum := i64(0)
|
||||
for _ in 0 .. 4 {
|
||||
sum += <-resch
|
||||
|
@ -16,14 +16,14 @@ fn do_send(ch chan int) {
|
||||
fn test_channel_multi_buffered() {
|
||||
ch := chan int{cap: 100}
|
||||
resch := chan i64{}
|
||||
go do_rec(ch, resch)
|
||||
go do_rec(ch, resch)
|
||||
go do_rec(ch, resch)
|
||||
go do_rec(ch, resch)
|
||||
go do_send(ch)
|
||||
go do_send(ch)
|
||||
go do_send(ch)
|
||||
go do_send(ch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_send(ch)
|
||||
spawn do_send(ch)
|
||||
spawn do_send(ch)
|
||||
spawn do_send(ch)
|
||||
mut sum := i64(0)
|
||||
for _ in 0 .. 4 {
|
||||
sum += <-resch
|
||||
|
@ -22,7 +22,7 @@ fn do_rec_calc_send(chs []chan mut St) {
|
||||
|
||||
fn test_channel_array_mut() {
|
||||
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{
|
||||
n: 100
|
||||
}
|
||||
|
@ -23,11 +23,11 @@ fn do_send(ch chan int) {
|
||||
fn test_channel_close_buffered_multi() {
|
||||
ch := chan int{cap: 10}
|
||||
resch := chan i64{}
|
||||
go do_rec(ch, resch)
|
||||
go do_rec(ch, resch)
|
||||
go do_rec(ch, resch)
|
||||
go do_rec(ch, resch)
|
||||
go do_send(ch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_send(ch)
|
||||
mut sum := i64(0)
|
||||
for _ in 0 .. 4 {
|
||||
sum += <-resch
|
||||
@ -38,11 +38,11 @@ fn test_channel_close_buffered_multi() {
|
||||
fn test_channel_close_unbuffered_multi() {
|
||||
ch := chan int{}
|
||||
resch := chan i64{}
|
||||
go do_rec(ch, resch)
|
||||
go do_rec(ch, resch)
|
||||
go do_rec(ch, resch)
|
||||
go do_rec(ch, resch)
|
||||
go do_send(ch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_send(ch)
|
||||
mut sum := i64(0)
|
||||
for _ in 0 .. 4 {
|
||||
sum += <-resch
|
||||
@ -53,8 +53,8 @@ fn test_channel_close_unbuffered_multi() {
|
||||
fn test_channel_close_buffered() {
|
||||
ch := chan int{cap: 100}
|
||||
resch := chan i64{}
|
||||
go do_rec(ch, resch)
|
||||
go do_send(ch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_send(ch)
|
||||
mut sum := i64(0)
|
||||
sum += <-resch
|
||||
assert sum == i64(8000) * (8000 - 1) / 2
|
||||
@ -63,8 +63,8 @@ fn test_channel_close_buffered() {
|
||||
fn test_channel_close_unbuffered() {
|
||||
ch := chan int{}
|
||||
resch := chan i64{cap: 100}
|
||||
go do_rec(ch, resch)
|
||||
go do_send(ch)
|
||||
spawn do_rec(ch, resch)
|
||||
spawn do_send(ch)
|
||||
mut sum := i64(0)
|
||||
sum += <-resch
|
||||
assert sum == i64(8000) * (8000 - 1) / 2
|
||||
@ -72,7 +72,7 @@ fn test_channel_close_unbuffered() {
|
||||
|
||||
fn test_channel_send_close_buffered() {
|
||||
ch := chan int{cap: 1}
|
||||
t := go fn (ch chan int) {
|
||||
t := spawn fn (ch chan int) {
|
||||
ch <- 31
|
||||
mut x := 45
|
||||
ch <- 17 or { x = -133 }
|
||||
@ -90,7 +90,7 @@ fn test_channel_send_close_buffered() {
|
||||
fn test_channel_send_close_unbuffered() {
|
||||
time.sleep(1 * time.second)
|
||||
ch := chan int{}
|
||||
t := go fn (ch chan int) {
|
||||
t := spawn fn (ch chan int) {
|
||||
mut x := 31
|
||||
ch <- 177 or { x = -71 }
|
||||
|
||||
|
@ -15,7 +15,7 @@ fn do_send(ch chan int, mut fin sync.Semaphore) {
|
||||
fn test_channel_len_cap() {
|
||||
ch := chan int{cap: queue_len}
|
||||
mut sem := sync.new_semaphore()
|
||||
go do_send(ch, mut sem)
|
||||
spawn do_send(ch, mut sem)
|
||||
sem.wait()
|
||||
assert ch.cap == queue_len
|
||||
assert ch.len == queue_fill
|
||||
|
@ -27,7 +27,7 @@ fn do_rec_calc_send(chs []chan i64, mut sem sync.Semaphore) {
|
||||
fn test_channel_array_mut() {
|
||||
mut chs := [chan i64{}, chan i64{cap: 10}]
|
||||
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)
|
||||
for _ in 0 .. num_iterations {
|
||||
chs[0] <- t
|
||||
|
@ -36,13 +36,13 @@ fn test_channel_polling() {
|
||||
ch := chan int{cap: buflen}
|
||||
resch := chan i64{}
|
||||
for _ in 0 .. nrec {
|
||||
go do_rec(ch, resch, objs_per_thread)
|
||||
spawn do_rec(ch, resch, objs_per_thread)
|
||||
}
|
||||
mut n := nobj
|
||||
for _ in 0 .. nsend {
|
||||
end := n
|
||||
n -= objs_per_thread
|
||||
go do_send(ch, n, end)
|
||||
spawn do_send(ch, n, end)
|
||||
}
|
||||
mut sum := i64(0)
|
||||
for _ in 0 .. nrec {
|
||||
|
@ -11,7 +11,7 @@ fn f(ch chan int) {
|
||||
|
||||
fn test_push_or_unbuffered() {
|
||||
ch := chan int{}
|
||||
go f(ch)
|
||||
spawn f(ch)
|
||||
mut j := 0
|
||||
for {
|
||||
ch <- j or { break }
|
||||
@ -23,7 +23,7 @@ fn test_push_or_unbuffered() {
|
||||
|
||||
fn test_push_or_buffered() {
|
||||
ch := chan int{cap: c}
|
||||
go f(ch)
|
||||
spawn f(ch)
|
||||
mut j := 0
|
||||
for {
|
||||
ch <- j or { break }
|
||||
@ -50,9 +50,9 @@ fn g(ch chan int, res chan int) {
|
||||
fn test_many_senders() {
|
||||
ch := chan int{}
|
||||
res := chan int{}
|
||||
go g(ch, res)
|
||||
go g(ch, res)
|
||||
go g(ch, res)
|
||||
spawn g(ch, res)
|
||||
spawn g(ch, res)
|
||||
spawn g(ch, res)
|
||||
mut k := 0
|
||||
for _ in 0 .. 3 * n {
|
||||
k = <-ch
|
||||
|
@ -16,7 +16,7 @@ fn do_send(ch chan f64, val f64) ?f64 {
|
||||
|
||||
fn test_push_propargate() {
|
||||
ch := chan f64{}
|
||||
go f(ch)
|
||||
spawn f(ch)
|
||||
mut s := 1.0
|
||||
for {
|
||||
s = do_send(ch, s) or { break }
|
||||
|
@ -31,10 +31,10 @@ fn test_select() {
|
||||
chl := chan i64{cap: 1}
|
||||
chb := chan u8{cap: 10}
|
||||
recch := chan i64{cap: 0}
|
||||
go do_rec_i64(recch)
|
||||
go do_send_int(chi)
|
||||
go do_send_u8(chb)
|
||||
go do_send_i64(chl)
|
||||
spawn do_rec_i64(recch)
|
||||
spawn do_send_int(chi)
|
||||
spawn do_send_u8(chb)
|
||||
spawn do_send_i64(chl)
|
||||
mut sum := i64(0)
|
||||
mut rl := i64(0)
|
||||
mut sl := i64(0)
|
||||
|
@ -79,7 +79,7 @@ fn test_select_blocks() {
|
||||
}
|
||||
assert r == true
|
||||
assert t == true
|
||||
go f2(ch2, ch3, mut sem)
|
||||
spawn f2(ch2, ch3, mut sem)
|
||||
n := <-ch3
|
||||
assert n == 23
|
||||
ch2 <- St{
|
||||
@ -87,7 +87,7 @@ fn test_select_blocks() {
|
||||
}
|
||||
sem.wait()
|
||||
stopwatch := time.new_stopwatch()
|
||||
go f1(ch1, ch2, ch3, ch4, ch5, mut sem)
|
||||
spawn f1(ch1, ch2, ch3, ch4, ch5, mut sem)
|
||||
sem.wait()
|
||||
elapsed_ms := f64(stopwatch.elapsed()) / time.millisecond
|
||||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/high-resolution-timers
|
||||
|
@ -16,8 +16,8 @@ fn test_select() {
|
||||
chi := chan int{cap: 10}
|
||||
recch := chan i64{cap: 10}
|
||||
chsum := chan i64{}
|
||||
go do_rec_i64(recch, chsum)
|
||||
go do_send_int(chi)
|
||||
spawn do_rec_i64(recch, chsum)
|
||||
spawn do_send_int(chi)
|
||||
mut sum := i64(0)
|
||||
mut sl := i64(0)
|
||||
for _ in 0 .. 60000 + recch.cap {
|
||||
|
@ -28,12 +28,12 @@ fn test_select() {
|
||||
chi := chan int{cap: 10}
|
||||
recch := chan i64{cap: 10}
|
||||
chsum := chan i64{}
|
||||
go do_rec_i64(recch, chsum)
|
||||
go do_rec_i64(recch, chsum)
|
||||
go do_rec_i64(recch, chsum)
|
||||
go do_send_int(chi)
|
||||
go do_send_int2(chi)
|
||||
go do_send_int3(chi)
|
||||
spawn do_rec_i64(recch, chsum)
|
||||
spawn do_rec_i64(recch, chsum)
|
||||
spawn do_rec_i64(recch, chsum)
|
||||
spawn do_send_int(chi)
|
||||
spawn do_send_int2(chi)
|
||||
spawn do_send_int3(chi)
|
||||
mut sum := i64(0)
|
||||
mut sl := i64(0)
|
||||
for _ in 0 .. 60000 + recch.cap {
|
||||
|
@ -51,15 +51,15 @@ fn test_select() {
|
||||
chsum2 := chan i64{}
|
||||
chsumf1 := chan f64{}
|
||||
chsumf2 := chan f64{}
|
||||
go do_send_int(ch1, 3)
|
||||
go do_select(ch1, ch2, chf1, chf2, chsum1, chsum2)
|
||||
go do_rec_f64(chf1, chsumf1)
|
||||
go do_rec_f64(chf2, chsumf2)
|
||||
go do_rec_f64(chf2, chsumf2)
|
||||
go do_select(ch1, ch2, chf1, chf2, chsum1, chsum2)
|
||||
go do_send_int(ch2, 7)
|
||||
go do_send_int(ch2, 17)
|
||||
go do_select(ch1, ch2, chf1, chf2, chsum1, chsum2)
|
||||
spawn do_send_int(ch1, 3)
|
||||
spawn do_select(ch1, ch2, chf1, chf2, chsum1, chsum2)
|
||||
spawn do_rec_f64(chf1, chsumf1)
|
||||
spawn do_rec_f64(chf2, chsumf2)
|
||||
spawn do_rec_f64(chf2, chsumf2)
|
||||
spawn do_select(ch1, ch2, chf1, chf2, chsum1, chsum2)
|
||||
spawn do_send_int(ch2, 7)
|
||||
spawn do_send_int(ch2, 17)
|
||||
spawn do_select(ch1, ch2, chf1, chf2, chsum1, chsum2)
|
||||
|
||||
sum1 := <-chsum1 + <-chsum1 + <-chsum1
|
||||
sum2 := <-chsum2 + <-chsum2 + <-chsum2
|
||||
|
@ -53,10 +53,10 @@ fn test_select() {
|
||||
mut chl := new_channel<i64>(1)
|
||||
mut chb := new_channel<u8>(10)
|
||||
mut recch := new_channel<i64>(0)
|
||||
go do_rec_i64(mut recch)
|
||||
go do_send_int(mut chi)
|
||||
go do_send_u8(mut chb)
|
||||
go do_send_i64(mut chl)
|
||||
spawn do_rec_i64(mut recch)
|
||||
spawn do_send_int(mut chi)
|
||||
spawn do_send_u8(mut chb)
|
||||
spawn do_send_i64(mut chl)
|
||||
mut channels := [chi, recch, chl, chb]
|
||||
directions := [Direction.pop, .push, .pop, .pop]
|
||||
mut sum := i64(0)
|
||||
|
@ -24,7 +24,7 @@ fn test_many_times_once() {
|
||||
|
||||
// It is executed 10 times, but only once actually.
|
||||
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++ {
|
||||
<-c
|
||||
@ -40,7 +40,7 @@ fn test_many_times_fifth() {
|
||||
|
||||
// It is executed 10 times, but only 5 times actually.
|
||||
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++ {
|
||||
<-c
|
||||
|
@ -24,7 +24,7 @@ fn test_once() {
|
||||
|
||||
// It is executed 10 times, but only once actually.
|
||||
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++ {
|
||||
<-c
|
||||
|
@ -29,7 +29,7 @@ fn test_once() {
|
||||
|
||||
// It is executed 10 times, but only once actually.
|
||||
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++ {
|
||||
<-c
|
||||
|
@ -89,7 +89,7 @@ pub fn (mut pool PoolProcessor) work_on_pointers(items []voidptr) {
|
||||
pool.waitgroup.add(njobs)
|
||||
for i := 0; i < njobs; i++ {
|
||||
if njobs > 1 {
|
||||
go process_in_thread(mut pool, i)
|
||||
spawn process_in_thread(mut pool, i)
|
||||
} else {
|
||||
// do not run concurrently, just use the same thread:
|
||||
process_in_thread(mut pool, i)
|
||||
|
@ -44,10 +44,10 @@ fn test_select() {
|
||||
mut chl := new_channel<i64>(1)
|
||||
mut chb := new_channel<u8>(10)
|
||||
mut recch := new_channel<i64>(0)
|
||||
go do_rec_i64(mut recch)
|
||||
go do_send_int(mut chi)
|
||||
go do_send_u8(mut chb)
|
||||
go do_send_i64(mut chl)
|
||||
spawn do_rec_i64(mut recch)
|
||||
spawn do_send_int(mut chi)
|
||||
spawn do_send_u8(mut chb)
|
||||
spawn do_send_i64(mut chl)
|
||||
mut channels := [chi, recch, chl, chb]
|
||||
directions := [Direction.pop, .push, .pop, .pop]
|
||||
mut sum := i64(0)
|
||||
|
@ -15,7 +15,7 @@ fn test_count_10_times_1_cycle_should_result_10_cycles_with_sync() {
|
||||
mut counter := &Counter{}
|
||||
wg.add(10)
|
||||
for i := 0; i < 10; i++ {
|
||||
go count_one_cycle(mut counter, mut wg)
|
||||
spawn count_one_cycle(mut counter, mut wg)
|
||||
}
|
||||
wg.wait()
|
||||
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{}
|
||||
wg.add(10)
|
||||
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()
|
||||
// Note: we do not assert here, just print, because sometimes by chance counter.counter may be == desired_iterations
|
||||
|
@ -8,7 +8,7 @@ fn f(st Abc) {
|
||||
|
||||
fn test_chan_init() {
|
||||
st := Abc{}
|
||||
go f(st)
|
||||
spawn f(st)
|
||||
i := <-st.ch
|
||||
assert i == 47
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ fn simple_thread() u64 {
|
||||
fn test_sync_thread_id() {
|
||||
mtid := sync.thread_id()
|
||||
eprintln('main thread_id: $sync.thread_id().hex()')
|
||||
x := go simple_thread()
|
||||
y := go simple_thread()
|
||||
x := spawn simple_thread()
|
||||
y := spawn simple_thread()
|
||||
xtid := x.wait()
|
||||
ytid := y.wait()
|
||||
eprintln('main thread_id: $sync.thread_id().hex()')
|
||||
|
@ -10,7 +10,7 @@ fn test_waitgroup_reuse() {
|
||||
|
||||
wg.add(1)
|
||||
mut executed := false
|
||||
go fn (mut wg WaitGroup, executed voidptr) {
|
||||
spawn fn (mut wg WaitGroup, executed voidptr) {
|
||||
defer {
|
||||
wg.done()
|
||||
}
|
||||
@ -28,7 +28,7 @@ fn test_waitgroup_reuse() {
|
||||
|
||||
fn test_waitgroup_no_use() {
|
||||
mut done := false
|
||||
go fn (done voidptr) {
|
||||
spawn fn (done voidptr) {
|
||||
time.sleep(1 * time.second)
|
||||
if *(&bool(done)) == false {
|
||||
panic('test_waitgroup_no_use did not complete in time')
|
||||
|
@ -252,7 +252,7 @@ fn (mut tasks Tasks) run() {
|
||||
}
|
||||
work.close()
|
||||
for _ in 0 .. vjobs {
|
||||
go work_processor(work, results)
|
||||
spawn work_processor(work, results)
|
||||
}
|
||||
if github_job == '' {
|
||||
println('')
|
||||
|
@ -1170,7 +1170,7 @@ pub fn (mut f Fmt) global_decl(node ast.GlobalDecl) {
|
||||
}
|
||||
|
||||
pub fn (mut f Fmt) go_expr(node ast.GoExpr) {
|
||||
f.write('go ')
|
||||
f.write('spawn ')
|
||||
f.call_expr(node.call_expr)
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ fn main() {
|
||||
for m, n in ma {
|
||||
iss := m
|
||||
}
|
||||
go async(0, 'hello')
|
||||
spawn async(0, 'hello')
|
||||
fn_in_var := fn (number int) {
|
||||
println('number: $number')
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ pub fn start_reloader(mut r live.LiveReloadInfo) {
|
||||
eprintln(err)
|
||||
exit(1)
|
||||
}
|
||||
go reloader(mut r)
|
||||
spawn reloader(mut r)
|
||||
}
|
||||
|
||||
fn elog(r &live.LiveReloadInfo, s string) {
|
||||
|
@ -3,7 +3,7 @@ import sync
|
||||
fn test_go_anon_fn() {
|
||||
mut wg := sync.new_waitgroup()
|
||||
wg.add(1)
|
||||
go fn (mut wg sync.WaitGroup) {
|
||||
spawn fn (mut wg sync.WaitGroup) {
|
||||
wg.done()
|
||||
}(mut wg)
|
||||
wg.wait()
|
||||
|
@ -35,8 +35,8 @@ fn test_array_map_ref() {
|
||||
a_ref[1] = 17
|
||||
}
|
||||
assert a_ref.len == 5
|
||||
t1 := go mod_map(shared m_shared)
|
||||
t2 := go mod_array(shared a_shared)
|
||||
t1 := spawn mod_map(shared m_shared)
|
||||
t2 := spawn mod_array(shared a_shared)
|
||||
lock m_shared, a_shared {
|
||||
a_shared[4] = -12.25
|
||||
m_shared['tz'] = 73.75
|
||||
|
@ -26,7 +26,7 @@ fn test_array_of_threads_wait() {
|
||||
println('Async')
|
||||
mut results := []thread f64{len: 16, cap: 16}
|
||||
for num in 0 .. 15 {
|
||||
results << go async(size, init_val + num)
|
||||
results << spawn async(size, init_val + num)
|
||||
}
|
||||
waited_results := results.wait()
|
||||
|
||||
|
@ -11,7 +11,7 @@ mut:
|
||||
fn test_atomic() {
|
||||
mut app := &App{}
|
||||
for i in 0 .. 10 {
|
||||
go app.run()
|
||||
spawn app.run()
|
||||
}
|
||||
time.sleep(200 * time.millisecond)
|
||||
println('idx=$app.idx')
|
||||
|
@ -13,8 +13,8 @@ fn add_elements(shared foo []int, n int) {
|
||||
|
||||
fn test_autolocked_array() {
|
||||
shared abc := &[0]
|
||||
go add_elements(shared abc, 1)
|
||||
go add_elements(shared abc, 3)
|
||||
spawn add_elements(shared abc, 1)
|
||||
spawn add_elements(shared abc, 3)
|
||||
for _ in 0 .. iterations_per_thread {
|
||||
abc << 0
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ fn inc_elements(shared foo []int, n int, mut sem sync.Semaphore) {
|
||||
fn test_autolocked_array_2() {
|
||||
shared abc := &[0, 0, 0]
|
||||
mut sem := sync.new_semaphore()
|
||||
go inc_elements(shared abc, 1, mut sem)
|
||||
go inc_elements(shared abc, 2, mut sem)
|
||||
spawn inc_elements(shared abc, 1, mut sem)
|
||||
spawn inc_elements(shared abc, 2, mut sem)
|
||||
for _ in 0 .. iterations_per_thread2 {
|
||||
unsafe {
|
||||
abc[2]++
|
||||
|
@ -54,7 +54,7 @@ fn main() {
|
||||
eprintln('usage:\n\t${os.args[0]} [num_iterations]')
|
||||
exit(1)
|
||||
}
|
||||
go waste_mem()
|
||||
spawn waste_mem()
|
||||
mut last := time.sys_mono_now()
|
||||
for _ in 0 .. n_iterations {
|
||||
now := time.sys_mono_now()
|
||||
|
@ -13,8 +13,8 @@ const (
|
||||
fn test_return_lock() {
|
||||
start := time.now()
|
||||
shared s := AA{'3'}
|
||||
go printer(shared s, start)
|
||||
go fn (shared s AA, start time.Time) {
|
||||
spawn printer(shared s, start)
|
||||
spawn fn (shared s AA, start time.Time) {
|
||||
for {
|
||||
reader(shared s)
|
||||
if time.now() - start > run_time {
|
||||
|
@ -18,7 +18,7 @@ fn test_printing_of_channels() {
|
||||
val: 1000
|
||||
another: fch
|
||||
}
|
||||
res := (go fn1(ch)).wait()
|
||||
res := (spawn fn1(ch)).wait()
|
||||
println(res)
|
||||
println(ch)
|
||||
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() {
|
||||
a := chan As{}
|
||||
go func(a)
|
||||
spawn func(a)
|
||||
ret := <-a
|
||||
println(ret)
|
||||
assert '$ret' == 'As(Aa{})'
|
||||
|
@ -16,7 +16,7 @@ fn test_comptime_if_expr_of_threads() {
|
||||
println('Async')
|
||||
mut results := []thread f64{cap: 16}
|
||||
for num in 0 .. 15 {
|
||||
results << go async(size, num)
|
||||
results << spawn async(size, num)
|
||||
}
|
||||
waited_results := results.wait()
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
fn abc() {
|
||||
go fn () {}()
|
||||
spawn fn () {}()
|
||||
}
|
||||
|
||||
fn test_if_threads() {
|
||||
|
@ -20,7 +20,7 @@ fn test_default_stack_depth() {
|
||||
// and would have failed on macos, where the default thread size
|
||||
// is just 512KB, if V was not changed to have a default for
|
||||
// `-thread-stack-size` of 8MB.
|
||||
t := go abc(10)
|
||||
t := spawn abc(10)
|
||||
res := t.wait()
|
||||
assert res == 55
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ fn test_defer_with_anon_fn() {
|
||||
assert f.add(1) == 111
|
||||
}
|
||||
|
||||
go fn () {
|
||||
spawn fn () {
|
||||
defer {
|
||||
println('deferred 1')
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ module main
|
||||
|
||||
fn test_fixed_array_of_threads() {
|
||||
mut avar := [8]thread string{}
|
||||
avar[0] = go printme()
|
||||
avar[0] = spawn printme()
|
||||
ret := avar[0].wait()
|
||||
assert ret == 'me'
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ fn test_for_match() {
|
||||
fn test_for_select() {
|
||||
ch1 := chan int{}
|
||||
ch2 := chan f64{}
|
||||
go do_send(ch1, ch2)
|
||||
spawn do_send(ch1, ch2)
|
||||
mut a := 0
|
||||
mut b := 0
|
||||
for select {
|
||||
|
@ -6,7 +6,7 @@ fn test_go_anon_fn_call_with_ref_arg() {
|
||||
foo := &Foo{
|
||||
bar: 'hello'
|
||||
}
|
||||
g := go fn (foo Foo) string {
|
||||
g := spawn fn (foo Foo) string {
|
||||
return foo.bar
|
||||
}(foo)
|
||||
ret := g.wait()
|
||||
|
@ -7,7 +7,7 @@ fn sum1(a int, b int) int {
|
||||
}
|
||||
sum_func2 := sum_func1
|
||||
|
||||
g := go sum_func2(a, b)
|
||||
g := spawn sum_func2(a, b)
|
||||
|
||||
result := g.wait()
|
||||
return result
|
||||
@ -21,7 +21,7 @@ fn sum2(a int, b int) int {
|
||||
sum_func1 := add
|
||||
sum_func2 := sum_func1
|
||||
|
||||
g := go sum_func2(a, b)
|
||||
g := spawn sum_func2(a, b)
|
||||
|
||||
result := g.wait()
|
||||
return result
|
||||
|
@ -9,7 +9,7 @@ fn f(x f64) f64 {
|
||||
fn test_array_thread_f64_wait() {
|
||||
mut r := []thread f64{cap: 10}
|
||||
for i in 0 .. 10 {
|
||||
r << go f(f64(i) + 0.5)
|
||||
r << spawn f(f64(i) + 0.5)
|
||||
}
|
||||
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]
|
||||
@ -24,13 +24,13 @@ fn g(shared a []int, i int) {
|
||||
fn test_array_thread_void_wait() {
|
||||
shared a := [2, 3, 5, 7, 11, 13, 17]
|
||||
t := [
|
||||
go g(shared a, 0),
|
||||
go g(shared a, 3),
|
||||
go g(shared a, 6),
|
||||
go g(shared a, 2),
|
||||
go g(shared a, 1),
|
||||
go g(shared a, 5),
|
||||
go g(shared a, 4),
|
||||
spawn g(shared a, 0),
|
||||
spawn g(shared a, 3),
|
||||
spawn g(shared a, 6),
|
||||
spawn g(shared a, 2),
|
||||
spawn g(shared a, 1),
|
||||
spawn g(shared a, 5),
|
||||
spawn g(shared a, 4),
|
||||
]
|
||||
println('threads started')
|
||||
t.wait()
|
||||
@ -43,9 +43,9 @@ fn test_void_thread_decl() {
|
||||
shared a := [2, 3, 9]
|
||||
mut t1 := thread(0)
|
||||
mut tarr := []thread{len: 2}
|
||||
t1 = go g(shared a, 0)
|
||||
tarr[0] = go g(shared a, 1)
|
||||
tarr[1] = go g(shared a, 2)
|
||||
t1 = spawn g(shared a, 0)
|
||||
tarr[0] = spawn g(shared a, 1)
|
||||
tarr[1] = spawn g(shared a, 2)
|
||||
t1.wait()
|
||||
tarr.wait()
|
||||
rlock a {
|
||||
|
@ -6,7 +6,7 @@ fn test_go_call_anon_fn_with_closure1() {
|
||||
return a
|
||||
}
|
||||
|
||||
g := go b()
|
||||
g := spawn b()
|
||||
ret := g.wait()
|
||||
assert ret == 1
|
||||
}
|
||||
@ -17,7 +17,7 @@ fn test_go_call_anon_fn_with_closure2() {
|
||||
'key2': 2
|
||||
}
|
||||
|
||||
h := go fn [m] () int {
|
||||
h := spawn fn [m] () int {
|
||||
println(m['key2'])
|
||||
return m['key2']
|
||||
}()
|
||||
|
@ -1,7 +1,7 @@
|
||||
const text = 'Hello world'
|
||||
|
||||
fn test_go_call_fn_return() {
|
||||
hex_go := go text.bytes().hex()
|
||||
hex_go := spawn text.bytes().hex()
|
||||
hex := text.bytes().hex()
|
||||
|
||||
assert hex == '48656c6c6f20776f726c64'
|
||||
|
@ -8,7 +8,7 @@ fn test_go_call_fn_using_map_value() {
|
||||
mut fns := map[string]fn (int, int) int{}
|
||||
fns['sum'] = sum
|
||||
|
||||
g := go fns['sum'](2, 3)
|
||||
g := spawn fns['sum'](2, 3)
|
||||
x := g.wait()
|
||||
|
||||
println('$x')
|
||||
|
@ -8,7 +8,7 @@ fn on_connect() {
|
||||
}
|
||||
|
||||
fn test_go_call_fn_with_anon_fn_arg() {
|
||||
g := go start(on_connect)
|
||||
g := spawn start(on_connect)
|
||||
ret := g.wait()
|
||||
assert ret == 'ok!!'
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ fn test<T>(c chan int, s T) {
|
||||
|
||||
fn test_go_generic_fn() {
|
||||
mut c := chan int{}
|
||||
go test<string>(c, 'abcd')
|
||||
spawn test<string>(c, 'abcd')
|
||||
x := <-c
|
||||
assert x == 123
|
||||
println('bye')
|
||||
|
@ -21,7 +21,7 @@ fn test_go_call_interface_method() {
|
||||
tasks << Task2{}
|
||||
|
||||
for task in tasks {
|
||||
go task.task()
|
||||
spawn task.task()
|
||||
}
|
||||
|
||||
assert true
|
||||
|
@ -3,7 +3,7 @@ fn create_random_frames(amount int, pixels int) [][][]int {
|
||||
}
|
||||
|
||||
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()
|
||||
assert res == [[[2, 2]]]
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ fn f(x int, y f64) f64 {
|
||||
}
|
||||
|
||||
fn test_go_return() {
|
||||
r := go f(3, 4.0)
|
||||
r := spawn f(3, 4.0)
|
||||
z := r.wait()
|
||||
assert typeof(z).name == 'f64'
|
||||
assert z == 12.0
|
||||
|
@ -15,7 +15,7 @@ fn f(x int, y f64, shared s St) {
|
||||
|
||||
fn test_go_return() {
|
||||
shared t := &St{}
|
||||
r := go f(3, 4.0, shared t)
|
||||
r := spawn f(3, 4.0, shared t)
|
||||
r.wait()
|
||||
rlock t {
|
||||
assert t.x == 12.0
|
||||
|
@ -12,7 +12,7 @@ fn test_method_go_wait() {
|
||||
test: 'hi'
|
||||
}
|
||||
}
|
||||
thread := go a.sub.get()
|
||||
thread := spawn a.sub.get()
|
||||
r := thread.wait()
|
||||
assert r == 'hi'
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ fn g(n int) ? {
|
||||
}
|
||||
|
||||
fn test_opt_val_wait() {
|
||||
h1 := go f(-1)
|
||||
h2 := go f(3)
|
||||
h1 := spawn f(-1)
|
||||
h2 := spawn f(3)
|
||||
r1 := h1.wait() or { 17.0 }
|
||||
r2 := h2.wait() or { 23.0 }
|
||||
assert r1 == 17.0
|
||||
@ -26,8 +26,8 @@ fn test_opt_val_wait() {
|
||||
}
|
||||
|
||||
fn test_opt_void_wait() {
|
||||
h1 := go g(2)
|
||||
h2 := go g(3)
|
||||
h1 := spawn g(2)
|
||||
h2 := spawn g(3)
|
||||
mut x := 0
|
||||
mut y := 0
|
||||
h1.wait() or { x = 1 }
|
||||
@ -37,8 +37,8 @@ fn test_opt_void_wait() {
|
||||
}
|
||||
|
||||
fn propagate(n int, m int) ?f64 {
|
||||
h1 := go f(n)
|
||||
h2 := go g(m)
|
||||
h1 := spawn f(n)
|
||||
h2 := spawn g(m)
|
||||
r := h1.wait()?
|
||||
h2.wait()?
|
||||
return r
|
||||
@ -56,7 +56,7 @@ fn test_propagate() {
|
||||
fn test_array_void_interate() {
|
||||
mut r := []thread ?{}
|
||||
for i in 0 .. 3 {
|
||||
r << go g(i)
|
||||
r << spawn g(i)
|
||||
}
|
||||
mut res := []int{len: 3, init: 17}
|
||||
for i, t in r {
|
||||
@ -70,7 +70,7 @@ fn test_array_void_interate() {
|
||||
fn test_array_val_interate() {
|
||||
mut r := []thread ?f64{}
|
||||
for i in -1 .. 2 {
|
||||
r << go f(i)
|
||||
r << spawn f(i)
|
||||
}
|
||||
mut res := []f64{len: 3}
|
||||
for i, t in r {
|
||||
@ -94,15 +94,15 @@ fn get_only_a_result_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 }
|
||||
t2 := go get_only_a_option_return(false)
|
||||
t2 := spawn get_only_a_option_return(false)
|
||||
t2.wait() or { assert true }
|
||||
assert true
|
||||
}
|
||||
|
||||
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 }
|
||||
assert true
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user