File: README.md

package info (click to toggle)
rust-wasmtimer 0.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 300 kB
  • sloc: makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,369 bytes parent folder | download
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# wasmtimer-rs

An implementation of `time` based functionalities from `std::time`, `tokio::time`,
`tokio_util::time` for WASM targets. This crate tries to closely
replicate above APIs. Users only have to change their `use` scripts by
using a `cfg` macro.

```rust
#[cfg(not(target_family="wasm"))]
use tokio::time::*;
#[cfg(target_family="wasm")]
use wasmtimer::tokio::*;
```

Check the [API Documentation](https://docs.rs/wasmtimer) for more
details.

## Story

Core idea and core modules in `src/timer` folder were copied from
[this](https://github.com/tomaka/wasm-timer) crate. This crate is
abandoned now due to lack of maintainability. I've hard forked it,
added some additional features and released to use for
[this](https://github.com/google/tarpc/pull/388) PR.

## `tokio::time` vs `wasmtimer`

- `wasmtimer` is only running on WASM browser targets and not using any
`tokio` feature as a dependency.
- This timer crate not supporting
[Auto-advance](https://docs.rs/tokio/latest/tokio/time/fn.pause.html#auto-advance)
like in the tokio crate. Because we can not track the background
tasks(`Promise`) in browser scope. If we implemented such without caring
about background tasks, then this implementation will not match with the
tokio's original implementation.

## Features

- Serde Support (`serde` feature flag)
- Worker and NodeJS Support
- Test Utilities