MCPcopy Create free account
hub / github.com/endbasic/endbasic / sleep

Method sleep

web/src/datetime.rs:88–99  ·  view source on GitHub ↗
(&self, d: Duration)

Source from the content-addressed store, hash-verified

86 }
87
88 async fn sleep(&self, d: Duration) -> Result<(), String> {
89 let ms = d.as_millis();
90 if ms > i32::MAX as u128 {
91 // The JavaScript setTimeout function only takes i32s so ensure our value fits. If it
92 // doesn't, you can imagine chaining calls to setTimeout to achieve the desired delay...
93 // but the numbers we are talking about are so big that this doesn't make sense.
94 return Err("Cannot sleep for that long".to_owned());
95 }
96
97 self.yielder.on_host_yield();
98 do_sleep(ms as i32, Ok(())).await
99 }
100}
101
102#[cfg(test)]

Callers 1

test_sleep_okFunction · 0.45

Calls 2

do_sleepFunction · 0.85
on_host_yieldMethod · 0.80

Tested by 1

test_sleep_okFunction · 0.36