time: time.wait() => time.sleep()

pull/9004/head
Alexander Medvednikov 2021-02-27 20:41:06 +03:00
parent be4a2e17d3
commit 3a2d696fac
42 changed files with 76 additions and 67 deletions

View File

@ -36,6 +36,6 @@ fn main() {
os.system('git push origin gh-pages') os.system('git push origin gh-pages')
os.chdir('..') os.chdir('..')
} }
time.wait(60 * time.second) time.sleep(60 * time.second)
} }
} }

View File

@ -44,7 +44,7 @@ fn (mut ctx Context) println(s string) {
fn do_timeout(c &Context) { fn do_timeout(c &Context) {
mut ctx := c mut ctx := c
time.wait(ctx.timeout_ms * time.millisecond) time.sleep(ctx.timeout_ms * time.millisecond)
exit(ctx.exitcode) exit(ctx.exitcode)
} }
@ -76,7 +76,7 @@ fn main() {
go do_timeout(&ctx) go do_timeout(&ctx)
for i := 1; true; i++ { for i := 1; true; i++ {
ctx.println('$i') ctx.println('$i')
time.wait(ctx.period_ms * time.millisecond) time.sleep(ctx.period_ms * time.millisecond)
} }
time.wait(100 * time.second) time.sleep(100 * time.second)
} }

View File

@ -60,7 +60,7 @@ fn main() {
source = source[..context.cut_index] source = source[..context.cut_index]
go fn (ms int) { go fn (ms int) {
time.wait(ms * time.millisecond) time.sleep(ms * time.millisecond)
exit(ecode_timeout) exit(ecode_timeout)
}(context.timeout_ms) }(context.timeout_ms)
_ := parser.parse_text(source, context.path, context.table, .skip_comments, context.pref, _ := parser.parse_text(source, context.path, context.table, .skip_comments, context.pref,
@ -259,7 +259,7 @@ fn (mut context Context) start_printing() {
fn (mut context Context) stop_printing() { fn (mut context Context) stop_printing() {
context.stop_print = true context.stop_print = true
time.wait(time.millisecond * context.period_ms / 5) time.sleep(time.millisecond * context.period_ms / 5)
} }
fn (mut context Context) print_status() { fn (mut context Context) print_status() {
@ -284,7 +284,7 @@ fn (mut context Context) print_periodic_status() {
for !context.stop_print { for !context.stop_print {
context.print_status() context.print_status()
for i := 0; i < 10 && !context.stop_print; i++ { for i := 0; i < 10 && !context.stop_print; i++ {
time.wait(time.millisecond * context.period_ms / 10) time.sleep(time.millisecond * context.period_ms / 10)
if context.cut_index > 50 && !printed_at_least_once { if context.cut_index > 50 && !printed_at_least_once {
context.print_status() context.print_status()
printed_at_least_once = true printed_at_least_once = true

View File

@ -14,6 +14,6 @@ fn main() {
l := r.read_line() or { break } l := r.read_line() or { break }
println('$l') println('$l')
// Make it nice and obvious that we are doing this line by line // Make it nice and obvious that we are doing this line by line
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
} }
} }

View File

@ -3,7 +3,7 @@ import time
// Simulate expensive computing using sleep function // Simulate expensive computing using sleep function
fn expensive_computing(id int, duration int) { fn expensive_computing(id int, duration int) {
println('Executing expensive computing task ($id)...') println('Executing expensive computing task ($id)...')
time.wait(duration * time.millisecond) time.sleep(duration * time.millisecond)
println('Finish task $id on $duration ms') println('Finish task $id on $duration ms')
} }

View File

@ -206,7 +206,7 @@ fn main() {
fn (mut app App) run() { fn (mut app App) run() {
for { for {
app.update() app.update()
time.wait(app.timer_period_ms * time.millisecond) time.sleep(app.timer_period_ms * time.millisecond)
} }
} }

View File

@ -20,6 +20,6 @@ fn main() {
for { for {
a.update() a.update()
print_automaton(a) print_automaton(a)
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
} }
} }

View File

@ -80,6 +80,6 @@ fn (mut game Game) update_model() {
fn (mut game Game) run() { fn (mut game Game) run() {
for { for {
game.update_model() game.update_model()
time.wait(16 * time.millisecond) // 60fps time.sleep(16 * time.millisecond) // 60fps
} }
} }

View File

@ -13,6 +13,6 @@ fn print_message() {
fn main() { fn main() {
for { for {
print_message() print_message()
time.wait(500 * time.millisecond) time.sleep(500 * time.millisecond)
} }
} }

View File

@ -30,7 +30,7 @@ fn (l Lander) open_parachutes(n int) {
fn wait() { fn wait() {
println('waiting...') println('waiting...')
time.wait(1 * time.second) time.sleep(1 * time.second)
} }
fn (l Lander) land(w World) { fn (l Lander) land(w World) {

View File

@ -37,6 +37,6 @@ fn main() {
audio.setup( audio.setup(
stream_cb: my_audio_stream_callback stream_cb: my_audio_stream_callback
) )
time.wait(2000 * time.millisecond) time.sleep(2000 * time.millisecond)
audio.shutdown() audio.shutdown()
} }

View File

@ -72,7 +72,7 @@ fn (mut p Player) play_wav_file(fpath string) ? {
p.samples << samples p.samples << samples
p.finished = false p.finished = false
for !p.finished { for !p.finished {
time.wait(16 * time.millisecond) time.sleep(16 * time.millisecond)
} }
p.free() p.free()
} }

View File

@ -218,7 +218,7 @@ fn (mut g Game) run() {
g.delete_completed_lines() g.delete_completed_lines()
} }
// glfw.post_empty_event() // force window redraw // glfw.post_empty_event() // force window redraw
time.wait(timer_period * time.millisecond) time.sleep(timer_period * time.millisecond)
} }
} }

View File

@ -32,7 +32,7 @@ fn (mut app App) sse() vweb.Result {
data := '{"time": "$time.now().str()", "random_id": "$rand.ulid()"}' data := '{"time": "$time.now().str()", "random_id": "$rand.ulid()"}'
session.send_message(event: 'ping', data: data) or { return app.server_error(501) } session.send_message(event: 'ping', data: data) or { return app.server_error(501) }
println('> sent event: $data') println('> sent event: $data')
time.wait(1 * time.second) time.sleep(1 * time.second)
} }
return app.server_error(501) return app.server_error(501)
} }

View File

@ -7,7 +7,7 @@ import x.websocket
fn main() { fn main() {
println('press enter to quit...\n') println('press enter to quit...\n')
go start_server() go start_server()
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
go start_client() go start_client()
os.get_line() os.get_line()
} }
@ -76,7 +76,7 @@ fn write_echo(mut ws websocket.Client) ? {
for i := 0; i <= 10; i++ { for i := 0; i <= 10; i++ {
// Server will send pings every 30 seconds // Server will send pings every 30 seconds
ws.write_str(message) or { println('panicing writing $err') } ws.write_str(message) or { println('panicing writing $err') }
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
} }
ws.close(1000, 'normal') or { println('panicing $err') } ws.close(1000, 'normal') or { println('panicing $err') }
} }

View File

@ -73,7 +73,7 @@ fn (cb &Clipboard) get_clipboard_lock() bool {
} else if last_error != u32(C.ERROR_ACCESS_DENIED) { } else if last_error != u32(C.ERROR_ACCESS_DENIED) {
return false return false
} }
time.wait(cb.retry_delay * time.second) time.sleep(cb.retry_delay * time.second)
} }
C.SetLastError(last_error) C.SetLastError(last_error)
return false return false

View File

@ -239,7 +239,7 @@ pub fn (mut cb Clipboard) set_text(text string) bool {
C.XFlush(cb.display) C.XFlush(cb.display)
cb.mutex.unlock() cb.mutex.unlock()
// sleep a little bit // sleep a little bit
time.wait(1 * time.millisecond) time.sleep(1 * time.millisecond)
return cb.is_owner return cb.is_owner
} }
@ -262,7 +262,7 @@ fn (mut cb Clipboard) get_text() string {
if cb.got_text || retries == 0 { if cb.got_text || retries == 0 {
break break
} }
time.wait(50 * time.millisecond) time.sleep(50 * time.millisecond)
retries-- retries--
} }
return cb.text return cb.text

View File

@ -39,7 +39,7 @@ fn test_run() {
$if trace_process_output ? { $if trace_process_output ? {
os.system('ps -opid= -oppid= -ouser= -onice= -of= -ovsz= -orss= -otime= -oargs= -p $p.pid') os.system('ps -opid= -oppid= -ouser= -onice= -of= -ovsz= -orss= -otime= -oargs= -p $p.pid')
} }
time.wait(50 * time.millisecond) time.sleep(50 * time.millisecond)
i++ i++
} }
p.wait() p.wait()

View File

@ -53,9 +53,9 @@ fn test_ulids_generated_in_the_same_millisecond_have_the_same_prefix() {
fn test_ulids_should_be_lexicographically_ordered_when_not_in_same_millisecond() { fn test_ulids_should_be_lexicographically_ordered_when_not_in_same_millisecond() {
ulid1 := rand.ulid() ulid1 := rand.ulid()
time.wait(1 * time.millisecond) time.sleep(1 * time.millisecond)
ulid2 := rand.ulid() ulid2 := rand.ulid()
time.wait(1 * time.millisecond) time.sleep(1 * time.millisecond)
ulid3 := rand.ulid() ulid3 := rand.ulid()
mut all := [ulid3, ulid2, ulid1] mut all := [ulid3, ulid2, ulid1]
// eprintln('all before: $all') // eprintln('all before: $all')

View File

@ -58,5 +58,5 @@ fn test_select() {
// the 3rd contribution is `byte` and must be seen modulo 256 // the 3rd contribution is `byte` and must be seen modulo 256
expected_sum := 2 * (300 * (300 - 1) / 2) + 256 * (256 - 1) / 2 + 44 * (44 - 1) / 2 expected_sum := 2 * (300 * (300 - 1) / 2) + 256 * (256 - 1) / 2 + 44 * (44 - 1) / 2
assert sum == expected_sum assert sum == expected_sum
time.wait(20 * time.millisecond) // to give assert in coroutine enough time time.sleep(20 * time.millisecond) // to give assert in coroutine enough time
} }

View File

@ -12,14 +12,14 @@ pub struct IResult {
fn worker_s(p &pool.PoolProcessor, idx int, worker_id int) &SResult { fn worker_s(p &pool.PoolProcessor, idx int, worker_id int) &SResult {
item := p.get_item<string>(idx) item := p.get_item<string>(idx)
println('worker_s worker_id: $worker_id | idx: $idx | item: $item') println('worker_s worker_id: $worker_id | idx: $idx | item: $item')
time.wait(3 * time.millisecond) time.sleep(3 * time.millisecond)
return &SResult{'$item $item'} return &SResult{'$item $item'}
} }
fn worker_i(p &pool.PoolProcessor, idx int, worker_id int) &IResult { fn worker_i(p &pool.PoolProcessor, idx int, worker_id int) &IResult {
item := p.get_item<int>(idx) item := p.get_item<int>(idx)
println('worker_i worker_id: $worker_id | idx: $idx | item: $item') println('worker_i worker_id: $worker_id | idx: $idx | item: $item')
time.wait(5 * time.millisecond) time.sleep(5 * time.millisecond)
return &IResult{item * 1000} return &IResult{item * 1000}
} }

View File

@ -107,7 +107,7 @@ pub fn (mut ctx Context) run() ? {
init_called = true init_called = true
} }
if sleep_len > 0 { if sleep_len > 0 {
time.wait(sleep_len * time.microsecond) time.sleep(sleep_len * time.microsecond)
} }
if !ctx.paused { if !ctx.paused {
sw.restart() sw.restart()

View File

@ -223,7 +223,7 @@ fn (mut ctx Context) termios_loop() {
} }
// println('SLEEPING: $sleep_len') // println('SLEEPING: $sleep_len')
if sleep_len > 0 { if sleep_len > 0 {
time.wait(sleep_len * time.microsecond) time.sleep(sleep_len * time.microsecond)
} }
if !ctx.paused { if !ctx.paused {
sw.restart() sw.restart()

View File

@ -7,7 +7,7 @@ fn test_stopwatch_works_as_intended() {
mut sw := time.new_stopwatch({}) mut sw := time.new_stopwatch({})
// sample code that you want to measure: // sample code that you want to measure:
println('Hello world') println('Hello world')
time.wait(1 * time.millisecond) time.sleep(1 * time.millisecond)
// //
println('Greeting the world took: ${sw.elapsed().nanoseconds()}ns') println('Greeting the world took: ${sw.elapsed().nanoseconds()}ns')
assert sw.elapsed().nanoseconds() > 0 assert sw.elapsed().nanoseconds() > 0
@ -16,18 +16,18 @@ fn test_stopwatch_works_as_intended() {
fn test_stopwatch_time_between_pause_and_start_should_be_skipped_in_elapsed() { fn test_stopwatch_time_between_pause_and_start_should_be_skipped_in_elapsed() {
println('Testing pause function') println('Testing pause function')
mut sw := time.new_stopwatch({}) mut sw := time.new_stopwatch({})
time.wait(10 * time.millisecond) // A time.sleep(10 * time.millisecond) // A
eprintln('Elapsed after 10ms nap: ${sw.elapsed().milliseconds()}ms') eprintln('Elapsed after 10ms nap: ${sw.elapsed().milliseconds()}ms')
assert sw.elapsed().milliseconds() >= 8 // sometimes it sleeps for 9ms on windows.. assert sw.elapsed().milliseconds() >= 8 // sometimes it sleeps for 9ms on windows..
sw.pause() sw.pause()
time.wait(10 * time.millisecond) time.sleep(10 * time.millisecond)
eprintln('Elapsed after pause and another 10ms nap: ${sw.elapsed().milliseconds()}ms') eprintln('Elapsed after pause and another 10ms nap: ${sw.elapsed().milliseconds()}ms')
assert sw.elapsed().milliseconds() >= 8 assert sw.elapsed().milliseconds() >= 8
$if stopwatch ? { $if stopwatch ? {
assert sw.elapsed().milliseconds() < 20 assert sw.elapsed().milliseconds() < 20
} }
sw.start() sw.start()
time.wait(10 * time.millisecond) // B time.sleep(10 * time.millisecond) // B
eprintln('Elapsed after resume and another 10ms nap: ${sw.elapsed().milliseconds()}ms') eprintln('Elapsed after resume and another 10ms nap: ${sw.elapsed().milliseconds()}ms')
assert sw.elapsed().milliseconds() >= 18 assert sw.elapsed().milliseconds() >= 18
$if stopwatch ? { $if stopwatch ? {

View File

@ -324,20 +324,22 @@ pub fn ticks() i64 {
// # return (double)(* (uint64_t *) &elapsedNano) / 1000000; // # return (double)(* (uint64_t *) &elapsedNano) / 1000000;
} }
/*
// sleep makes the calling thread sleep for a given number of seconds. // sleep makes the calling thread sleep for a given number of seconds.
[deprecated: 'call time.wait(n * time.second)'] [deprecated: 'call time.sleep(n * time.second)']
pub fn sleep(seconds int) { pub fn sleep(seconds int) {
wait(seconds * time.second) wait(seconds * time.second)
} }
*/
// sleep_ms makes the calling thread sleep for a given number of milliseconds. // sleep_ms makes the calling thread sleep for a given number of milliseconds.
[deprecated: 'call time.wait(n * time.millisecond)'] [deprecated: 'call time.sleep(n * time.millisecond)']
pub fn sleep_ms(milliseconds int) { pub fn sleep_ms(milliseconds int) {
wait(milliseconds * time.millisecond) wait(milliseconds * time.millisecond)
} }
// usleep makes the calling thread sleep for a given number of microseconds. // usleep makes the calling thread sleep for a given number of microseconds.
[deprecated: 'call time.wait(n * time.microsecond)'] [deprecated: 'call time.sleep(n * time.microsecond)']
pub fn usleep(microseconds int) { pub fn usleep(microseconds int) {
wait(microseconds * time.microsecond) wait(microseconds * time.microsecond)
} }

View File

@ -131,7 +131,14 @@ pub fn zero_timespec() C.timespec {
} }
// wait makes the calling thread sleep for a given duration (in nanoseconds). // wait makes the calling thread sleep for a given duration (in nanoseconds).
[deprecated: 'call time.sleep(n * time.second)']
pub fn wait(duration Duration) { pub fn wait(duration Duration) {
ts := &C.timespec{duration / second, duration % second} ts := &C.timespec{duration / second, duration % second}
C.nanosleep(ts, C.NULL) C.nanosleep(ts, C.NULL)
} }
// sleep makes the calling thread sleep for a given duration (in nanoseconds).
pub fn sleep(duration Duration) {
ts := &C.timespec{duration / second, duration % second}
C.nanosleep(ts, C.NULL)
}

View File

@ -208,7 +208,7 @@ fn test_utc() {
fn test_unix_time() { fn test_unix_time() {
t1 := time.utc() t1 := time.utc()
time.wait(50 * time.millisecond) time.sleep(50 * time.millisecond)
t2 := time.utc() t2 := time.utc()
ut1 := t1.unix_time() ut1 := t1.unix_time()
ut2 := t2.unix_time() ut2 := t2.unix_time()

View File

@ -160,7 +160,7 @@ fn reloader(mut r live.LiveReloadInfo) {
} }
} }
if r.recheck_period_ms > 0 { if r.recheck_period_ms > 0 {
time.wait(r.recheck_period_ms * time.millisecond) time.sleep(r.recheck_period_ms * time.millisecond)
} }
} }
} }

View File

@ -110,14 +110,14 @@ fn testsuite_end() {
} }
fn change_source(new string) { fn change_source(new string) {
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
vprintln('> change ORIGINAL to: $new') vprintln('> change ORIGINAL to: $new')
atomic_write_source(live_program_source.replace('ORIGINAL', new)) atomic_write_source(live_program_source.replace('ORIGINAL', new))
wait_for_file(new) wait_for_file(new)
} }
fn wait_for_file(new string) { fn wait_for_file(new string) {
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
expected_file := os.join_path(os.temp_dir(), new + '.txt') expected_file := os.join_path(os.temp_dir(), new + '.txt')
eprintln('waiting for $expected_file ...') eprintln('waiting for $expected_file ...')
max_wait_cycles := edefault('WAIT_CYCLES', '1').int() max_wait_cycles := edefault('WAIT_CYCLES', '1').int()
@ -128,10 +128,10 @@ fn wait_for_file(new string) {
if os.exists(expected_file) { if os.exists(expected_file) {
assert true assert true
vprintln('> done.') vprintln('> done.')
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
break break
} }
time.wait(5 * time.millisecond) time.sleep(5 * time.millisecond)
} }
} }

View File

@ -318,7 +318,7 @@ pub fn parse_files(paths []string, table &table.Table, pref &pref.Preferences, g
for _ in 0 .. nr_cpus - 1 { for _ in 0 .. nr_cpus - 1 {
go q.run() go q.run()
} }
time.wait(time.second) time.sleep(time.second)
println('all done') println('all done')
return q.parsed_ast_files return q.parsed_ast_files
} }

View File

@ -30,7 +30,7 @@ fn test_autolocked_array() {
if finished_threads == 2 { if finished_threads == 2 {
break break
} }
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
} }
// create histogram of results // create histogram of results
mut result := [0, 0, 0, 0] mut result := [0, 0, 0, 0]

View File

@ -6,7 +6,7 @@ mut:
} }
fn f(x int, y f64, shared s St) { fn f(x int, y f64, shared s St) {
time.wait(50 * time.millisecond) time.sleep(50 * time.millisecond)
lock s { lock s {
s.x = x * y s.x = x * y
} }

View File

@ -31,7 +31,7 @@ fn test_shared_array() {
if finished_threads == 4 { if finished_threads == 4 {
break break
} }
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
} }
rlock foo { rlock foo {
f0 := foo[0] f0 := foo[0]

View File

@ -44,7 +44,7 @@ fn test_shared_receiver_lock() {
if finished { if finished {
break break
} }
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
} }
rlock x, y { rlock x, y {
assert x.a == 7 && y.a == 5 assert x.a == 7 && y.a == 5

View File

@ -8,7 +8,7 @@ mut:
fn f(shared x St, shared z St) { fn f(shared x St, shared z St) {
for _ in 0 .. reads_per_thread { for _ in 0 .. reads_per_thread {
rlock x { // other instances may read at the same time rlock x { // other instances may read at the same time
time.wait(time.millisecond) time.sleep(time.millisecond)
assert x.a == 7 || x.a == 5 assert x.a == 7 || x.a == 5
} }
} }
@ -37,10 +37,10 @@ fn test_shared_lock() {
for i in 0 .. writes { for i in 0 .. writes {
lock x { // wait for ongoing reads to finish, don't start new ones lock x { // wait for ongoing reads to finish, don't start new ones
x.a = 17 // this should never be read x.a = 17 // this should never be read
time.wait(50 * time.millisecond) time.sleep(50 * time.millisecond)
x.a = if (i & 1) == 0 { 7 } else { 5 } x.a = if (i & 1) == 0 { 7 } else { 5 }
} // now new reads are possible again } // now new reads are possible again
time.wait(20 * time.millisecond) time.sleep(20 * time.millisecond)
} }
// wait until all read threads are finished // wait until all read threads are finished
for finished := false; true; { for finished := false; true; {
@ -52,6 +52,6 @@ fn test_shared_lock() {
if finished { if finished {
break break
} }
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
} }
} }

View File

@ -8,7 +8,7 @@ mut:
fn (shared x St) f(shared z St) { fn (shared x St) f(shared z St) {
for _ in 0 .. reads_per_thread { for _ in 0 .. reads_per_thread {
rlock x { // other instances may read at the same time rlock x { // other instances may read at the same time
time.wait(time.millisecond) time.sleep(time.millisecond)
assert x.a == 7 || x.a == 5 assert x.a == 7 || x.a == 5
} }
} }
@ -37,10 +37,10 @@ fn test_shared_lock() {
for i in 0 .. writes { for i in 0 .. writes {
lock x { // wait for ongoing reads to finish, don't start new ones lock x { // wait for ongoing reads to finish, don't start new ones
x.a = 17 // this value should never be read x.a = 17 // this value should never be read
time.wait(50 * time.millisecond) time.sleep(50 * time.millisecond)
x.a = if (i & 1) == 0 { 7 } else { 5 } x.a = if (i & 1) == 0 { 7 } else { 5 }
} // now new reads are possible again } // now new reads are possible again
time.wait(20 * time.millisecond) time.sleep(20 * time.millisecond)
} }
// wait until all read threads are finished // wait until all read threads are finished
for finished := false; true; { for finished := false; true; {
@ -52,6 +52,6 @@ fn test_shared_lock() {
if finished { if finished {
break break
} }
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
} }
} }

View File

@ -44,7 +44,7 @@ fn test_shared_lock() {
if finished { if finished {
break break
} }
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
} }
rlock x, y { rlock x, y {
assert x.a == 7 && y.a == 5 assert x.a == 7 && y.a == 5

View File

@ -511,7 +511,7 @@ pub fn prepare_tool_when_needed(source_name string) {
stool := os.join_path(vroot, 'cmd', 'tools', source_name) stool := os.join_path(vroot, 'cmd', 'tools', source_name)
tool_name, tool_exe := tool_source2name_and_exe(stool) tool_name, tool_exe := tool_source2name_and_exe(stool)
if should_recompile_tool(vexe, stool, tool_name, tool_exe) { if should_recompile_tool(vexe, stool, tool_name, tool_exe) {
time.wait(1001 * time.millisecond) // TODO: remove this when we can get mtime with a better resolution time.sleep(1001 * time.millisecond) // TODO: remove this when we can get mtime with a better resolution
recompile_file(vexe, stool) recompile_file(vexe, stool)
} }
} }

View File

@ -50,7 +50,7 @@ fn test_a_simple_vweb_app_runs_in_the_background() {
res := os.system(server_exec_cmd) res := os.system(server_exec_cmd)
assert res == 0 assert res == 0
} }
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
} }
// web client tests follow // web client tests follow
@ -238,7 +238,7 @@ fn simple_tcp_client(config SimpleTcpClientConfig) ?string {
if tries > config.retries { if tries > config.retries {
return error(err) return error(err)
} }
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
continue continue
} }
break break

View File

@ -15,7 +15,7 @@ struct App {
} }
fn exit_after_timeout(timeout_in_ms int) { fn exit_after_timeout(timeout_in_ms int) {
time.wait(timeout_in_ms * time.millisecond) time.sleep(timeout_in_ms * time.millisecond)
// eprintln('webserver is exiting ...') // eprintln('webserver is exiting ...')
exit(0) exit(0)
} }
@ -105,6 +105,6 @@ pub fn (mut app App) shutdown() vweb.Result {
fn (mut app App) gracefull_exit() { fn (mut app App) gracefull_exit() {
eprintln('>> webserver: gracefull_exit') eprintln('>> webserver: gracefull_exit')
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
exit(0) exit(0)
} }

View File

@ -72,7 +72,7 @@ fn (mut s Server) close() {
fn (mut s Server) handle_ping() { fn (mut s Server) handle_ping() {
mut clients_to_remove := []string{} mut clients_to_remove := []string{}
for s.state == .open { for s.state == .open {
time.wait(s.ping_interval * time.second) time.sleep(s.ping_interval * time.second)
for i, _ in s.clients { for i, _ in s.clients {
mut c := s.clients[i] mut c := s.clients[i]
if c.client.state == .open { if c.client.state == .open {

View File

@ -20,7 +20,7 @@ fn test_ws() {
} }
port := 30000 + rand.intn(1024) port := 30000 + rand.intn(1024)
go start_server(port) go start_server(port)
time.wait(500 * time.millisecond) time.sleep(500 * time.millisecond)
ws_test('ws://localhost:$port') or { assert false } ws_test('ws://localhost:$port') or { assert false }
} }
@ -92,10 +92,10 @@ fn ws_test(uri string) ? {
for msg in text { for msg in text {
ws.write(msg.bytes(), .text_frame) or { panic('fail to write to websocket') } ws.write(msg.bytes(), .text_frame) or { panic('fail to write to websocket') }
// sleep to give time to recieve response before send a new one // sleep to give time to recieve response before send a new one
time.wait(100 * time.millisecond) time.sleep(100 * time.millisecond)
} }
// sleep to give time to recieve response before asserts // sleep to give time to recieve response before asserts
time.wait(1500 * time.millisecond) time.sleep(1500 * time.millisecond)
// We expect at least 2 pongs, one sent directly and one indirectly // We expect at least 2 pongs, one sent directly and one indirectly
assert test_results.nr_pong_received >= 2 assert test_results.nr_pong_received >= 2
assert test_results.nr_messages == 2 assert test_results.nr_messages == 2