Hello Wasm Sleep and Time

Sleep

How to delay as sleep in Wasm.

  • std

    #![allow(unused)]
    fn main() {
      use std::thread::sleep;
      use std::time::Duration;
    
      sleep(Duration::from_secs(1));
    }
  • wasm

    #![allow(unused)]
    fn main() {
      use fluvio_wasm_timer::Delay;
      Delay::new(Duration::from_secs(1)).await.ok();
    }

SystemTime

How to get current time as UNIX_EPOCH in Wasm.

  • std

    #![allow(unused)]
    fn main() {
    use std::time::SystemTime;
    
    let now = SystemTime::now()
        .duration_since(SystemTime::UNIX_EPOCH)?
        .as_secs();
    }
  • wasm

    #![allow(unused)]
    fn main() {
    use fluvio_wasm_timer::SystemTime;
    
    let now = SystemTime::now()
        .duration_since(SystemTime::UNIX_EPOCH)?
        .as_secs();
    }