| 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)] |