wasmcloud-interface-timing

crates.io Documentation

Interface definition for the "wasmcloud:timing" capability contract. This contract allows actors to sleep for a specified duration, and also to retrieve the current system time on the wasmcloud host.

Useful for implementing rate limits or other time-based functionality, although it is important to take RPC timeouts into account when using this interface.

Example

```rust use wasmcloudinterfacetiming::TimingSender; use wasmbusrpc::actor::prelude::*; use wasmbusrpc::Timestamp;

async fn sleepfor5_seconds(ctx: &Context) -> RpcResult<()> { let timing = TimingSender::new(); timing.sleep(ctx, &5).await?; }

async fn sleepuntil5seconds(ctx: &Context) -> RpcResult<()> { let timing = TimingSender::new(); let now = sleepy::now(); let fiveseconds = Timestamp::new(now.sec + 5, now.nsec); timing.sleepuntil(ctx, &fiveseconds).await?; }

async fn getcurrenttime(ctx: &Context) -> RpcResult { let timing = TimingSender::new(); sleepy.now(ctx).await } ```