1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
use crate::{error::ZomeApiResult, Dispatch}; use holochain_json_api::json::JsonString; use std::time::Duration; /// Lets the DNA runtime sleep for the given duration. /// # Examples /// ```rust /// # #[macro_use] /// # extern crate hdk; /// # use hdk::error::ZomeApiResult; /// # use std::time::Duration; /// /// # fn main() { /// pub fn handle_some_function(content: String) -> ZomeApiResult<()> { /// // ... /// hdk::sleep(Duration::from_millis(100)); /// // ... /// Ok(()) /// } /// /// # } /// ``` pub fn sleep(duration: Duration) -> ZomeApiResult<()> { let _: ZomeApiResult<()> = Dispatch::Sleep.with_input(JsonString::from(duration.as_nanos())); // internally returns RibosomeEncodedValue::Success which is a zero length allocation // return Ok(()) unconditionally instead of the "error" from success Ok(()) }